Hello guys i am in level of class and objects
i need some help and guide in copy contruct i search the thread
and found 1 http://www.daniweb.com/forums/thread21662.html
but this is not what i want... ok here is the problem..
i created contruct class ... i want in program that create objects
on user input.. like how many computer you need.. if user enter 5
then compiler create 5 objects of class computer.. after that it asks
for computer specification and compiler then copy some contents to other
4 objects ... i coded the program it works perfect but the copy method copies
every contents of 1st object into others.. how can i copy some contents ..
this scenario is done with array object. please guide me if there is any better idea.
#include "iostream"
#include "string"
using namespace std;
class cmptr
{
private:
string rm;
string hd;
string nme;
string agp;
string mothrbrd;
int lcd;
int pcr;
public:
void defaultinfo()
{
cout<<"PC SPEC ";
cout<<"Enter pc name: ";
cin>>name;
cout<<"Enter processor speed: ";
cin>>pcr;
cout<<"Enter ram size: ";
cin>>ram;
cout<<"Enter motherboard model: ";
cin>>mothrbrd;
cout<<"Enter graphics card size: ";
cin>>agp;
cout<<"Enter lcd size: ";
cin>>lcd;
}
void all_other_info()
{
cout<<"Enter processor speed: ";
cin>>pcr;
cout<<"Enter ram size: ";
cin>>ram;
cout<<"Enter motherboard model: ";
cin>>mothrbrd;
}
void display()
{
cout<<"pc name: "<<name;
cout<<"processor speed:"<<pcr;
cout<<"ram size: "<<ram;
cout<<"motherboard model: "<<mothrbrd;
cout<<"graphics card size: "<<agp;
cout<<"lcd size: "<<lcd;
}
cmptr(cmptr &p)
{
name = p.name;
agp = p.agp;
lcd = p.lcd;
}
};
void main()
{
here are two codes this one works good
cmptr pc1;
cout<<"spec for 1 pc"<<endl;
pc1.defaultinfo();
cout<<"spec for 2 pc:"<<endl;
cmptr pc2=pc1; // here is copy 3 variables of pc1 not all
pc2.all_other_info(); // here it takes pc2 remaining values
cout<<"result of 1 pc"<<endl;
pc1.display();
cout<<"result of 2 pc"<<endl;
pc2.display();
// here is the real code which i am facing problem
int a;
cout<<"How many pc you want:"; // here i will enter 2 pc
cin>>a;
cmptr *pc = new cmptr[a];
pc[0].defaultinfo();
cmptr pc[1]=pc[0]; <--------- i get error from here
i want that some contents of pc1 array copy to
pc2 array contents but not working..
}