#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#define N 5
//apply following code for floating point operation in loop.
/*
void dummy(float *a){
//apply following code for floating point operation in loop.
/*
void dummy(float *a){
float
b=*a;
dummy(&b);
}
*/
class
product{
int pid;
char
pname[20];
float
costprice;
float
sellprice;
//inline function
void
profitloss(){
float pl;
pl=sellprice-costprice;
if(pl>0){
cout<<"Profit="<<pl<<endl;
}
else{
if(pl<0){
cout<<"Loss="<<pl<<endl;
}
else{
cout<<"NO
Profit - NO Loss"<<endl;
}
}}
public:
void
getproduct();
void
setproduct();
};
inline void
product::setproduct(){
cout<<"Enter
Product Details:"<<endl;
cout<<"Enter
Pid= ";
fflush(stdin);
cin>>pid;
getch();
cout<<"Enter
product name= ";
fflush(stdin);
cin>>pname;
getch();
cout<<"Costprice=
";
fflush(stdin);
cin>>costprice;
getch();
cout<<"Sellprice=
";
fflush(stdin);
cin>>sellprice;
getch();
}
void
product::getproduct(){
cout<<"Product
Details:"<<endl;
cout<<"pid="<<pid<<endl<<"product
name="<<pname<<endl<<"costprice=
"<<costprice<<endl<<"sellprice=
"<<sellprice<<endl;
profitloss();
}
void
main(){
product p[N];
clrscr();
int i;
for(i=0;i<N;i++) p[i].setproduct();
for(i=0;i<N;i++) p[i].getproduct();
getch();
}
No comments:
Post a Comment