Solved

How to program ?

Posted on 2000-04-23
4
221 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

11 Experts available now in Live!

Get 1:1 Help Now