how to pass a string value to a function in a class which is entered by user and already been initialized by constructor
in case 4 it doesn't ask to enter a string please tell me what is the problem
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
usingnamespace std;
class invoice{
private:
int partno,quantity,asd;
float price;
string description;
public:
int getpartno(){
return partno;
}
int getquantity(){
return quantity;
}
float getprice(){
return price;
}
string getdescription(){
return description;
}
int setpartno(int part){
partno=part;
}
int setquantity(int q){
if(q<0)
q=0;
quantity=q;
}
float setprice(float p){
if(p<0)
p=0;
price=p;
}
string setdescription(string d){
description=d;
}
void display(){
cout<<"\n--------------------------------------------------------------------------------";
cout<<"\nPart no is: "<<partno;
cout<<"\nQuantity of part is: "<<quantity;
cout<<"\nPrice fo thr part is: "<<price;
cout<<"\nDescription fo thr part is: \n\t"<<description<<endl;
}
void inv(){
cout<<"Total bill is: "<<quantity*price;
}
invoice(int pn,int qua,float pr,string des){
partno=pn;
quantity=qua;
price=pr;
description=des;
}
};
int main(){
string description="It is the excel of mehran car and made by suzuki iso 19001 sertified";
char z;
int partno=120,quantity=21;
float price=291.55 ;
invoice in(partno,quantity,price,description);
in.display();
aa:
cout<<"\nif you want to make some change in this info press number according to specific task----->>>>\n\t1.\tFor part no-->\n\t2.\tFor quantaty-->\n\t3.\tFor price-->\n\t4.\tFor Description-->\n\t5.\tFor continue-->\n";
int i;
cin>>i;
switch(i){
case 1:
cout<<"Enter new part no:";
cin>>partno;
in.setpartno(partno);
break;
case 2:
cout<<"Enter new Quantity:";
cin>>quantity;
in.setquantity(quantity);
break;
case 3:
cout<<"Enter new price:";
cin>>price;
in.setprice(price);
break;
case 4:
cout<<"Enter new description:";
getline(cin,description);
in.setdescription(description);
break;
default:
cout<<"\nContinued without making any change\n";
break;
}
in.display();
cout<<"If you stil want some change then press \"p\":";
cin>>z;
if(z=='p')
goto aa;
in.inv();
getch();
return 0;
}