Solved

How to program ?

Posted on 2000-04-23
4
230 Views
Last Modified: 2010-04-02
Design a class called Tvcctor with two private data members x and y to represent vector of two components as follow :

the class should have a default constructor to initialize both data members to zero, a general constructor to initialize both data members to given values on declaration and a copy constructor to initialize one object from another on declarationl;

the class should also have a member function set() to assign given values to the two data members.

Declare a vector class object a with the default constructor, declare another class object b with the general constructor, and initialize a third class object c with b.

0
Comment
Question by:pooiteng
  • 2
4 Comments
 
LVL 1

Expert Comment

by:ntdragon
ID: 2742288
we don't do homework at EE
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2743093
But we can *help* you to make it. Do you have a more specific question?
0
 

Accepted Solution

by:
sambitdash earned 100 total points
ID: 2807510
class Tvcctor {
double x;
double y;
public:
Tvcctor():x(0),y(0){}
Tvcctor(double x1, double y1):x(x1),y(y1){}
Tvcctor(const Tvcctor& t):x(t.x), y(t.y){}  // Default copy
                                    // ctor could have done
                     // not a must
set(double x1, double y1){x = x1; y = y1;}
};

int main(void){
Tvcctor a;
Tvcctor b(10, 5);
Tvcctor c(b);
}
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2808012
sambitdash, you are not really helping him. Think a bit on why student get assignments. Just dumping a few lines of code will not help pooiteng in learning C++.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now