
14-May-2008, 07:50
|
 |
Junior Member
|
|
Join Date: Mar 2008
Posts: 42
|
|
|
need help in OOP In C++
i want add the car details in car1 i want enter the model of the car through the user while in car2 i want the model to be already entered in the program it doesnt do my job...my code is here
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class car
{
char company[30],tyres[30],engine[30];
float price,power;
int model;
public:
void ReadData()
{
cout<<endl<<"Enter The Car Company Name :";
cin>>company;
cout<<"Enter The Tyres Name :";
cin>>tyres;
cout<<"Enter The Engine Name :";
cin>>engine;
//cout<<"Enter The Price Of The Car :";
// cin>>price;
cout<<"Enter The Engine Power :";
cin>>power;
// cout<<"Enter The Car Model :";
// cin>>model;
}
void PrintData()
{
cout<<"\nThe Company Name Is :"<<company;
cout<<"\nThe Tyres Company Name Is :"<<tyres;
cout<<"\nThe Engine Name Is :"<<engine;
cout<<"\nThe Price Of The Car Is :"<<price;
cout<<"\nThe Power Of The Engine Is :"<<power;
cout<<"\nThe Model Of The Car Is :"<<model;
}
car(float p,int q)
{
price=p;
model=q;
power=0;
strcpy(engine,"NA");
strcpy(tyres,"NA");
strcpy(company,"NA");
}
car(float p)
{
price=p;
model=0;
power=0;
strcpy(engine,"NA");
strcpy(tyres,"NA");
strcpy(company,"NA");
}
};
void main()
{
clrscr();
car car1(45.908f),car2(546.98f,2008);
car1.ReadData();
car2.ReadData();
car1.PrintData();
car2.PrintData();
getch();
}
__________________ K K K
Last edited by admin II : 14-May-2008 at 17:17.
Reason: Please surround your C++ code with [cpp] your code [/cpp]
|