Can anyone please tell me what is the problem in my code:
void Laptop::show()
{ Computer::show();
cout<<"weight is="<<weight<<endl;
cout<<"height is ="<<height<<endl;
cout<<"length is ="<<length<<endl;
cout<<"width is ="<<width<<endl;
}
I am unable to call
Computer::show(); function in Laptop::show(); function.Compiler says to use . or -> operator i am unable to understand.
Computer is base class and laptop is derived class.Code is given below.
#include<iostream.h>
#include<conio.h>
class Computer
{
protected:
int wordSize;
int memorySize;
int storageSize;
int speed;
public:
Computer(){}
Computer(int,int,int,int);
void show();
};
class Laptop
{
private:
int width;
int height;
int length;
int weight;
public:
Laptop(){}
Laptop(int,int,int,int,int,int,int,int);
void show();
};
Computer::Computer(int wdSize, int memSize, int storSize ,int spee)
{
wordSize=wdSize;
memorySize=memSize;
storageSize=storSize;
speed=spee;
}
void Computer::show()
{
cout<<"Word Size :"<<wordSize<<endl;
cout<<"Memory Size: "<<memorySize<<endl;
cout<<"Storage Size"<<storageSize<<endl;
cout<<"Speed :"<<speed;
}
Laptop::Laptop(int wdSize, int memSize,int storSize, int spee,int wid, int hei , int len , int wait ):Computer(wdSize,memSize,storSize,spee);
{
width=wid;
length=len;
height=hei;
weight=wait;
}
void Laptop::show()
{ Computer::show();
cout<<"weight is="<<weight<<endl;
cout<<"height is ="<<height<<endl;
cout<<"length is ="<<length<<endl;
cout<<"width is ="<<width<<endl;
}
void main()
{
clrscr();
Computer comp(4,512,20,2);
Laptop lap(8,1024,50,2,15,19,14,2);
cout<<"Computer Specifications are"<<endl;
comp.show();
cout<<":Laptop specifications are"<<endl;
lap.show();
getch();
}