Solved

How to program ?

Posted on 2000-04-23
4
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 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