Solved

How to program ?

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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 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.

738 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