Program
#include<iostream>using namespace std;
class car{
private:
int modelno,cost,partno;
public:
void setdata(int mn,int cst,int pn){
modelno=mn;// model number is assigned to mn
cost=cst; //cost is assigned to cst
partno=pn; // partno is assigned to pn
//These are all done because we can not directly access them coz of they are private
}
void showdata(){
cout<<"Model No="<<modelno<<endl;
cout<<"cost of car="<<cost<<endl;
cout<<"part number="<<partno;
}
};
int main(){
car c1;
c1.setdata(420,1000,12345);//Assigning values to the variable above
c1.showdata();//calling function showdata
return 0;
}
No comments: