Popular Posts

6/24/2012

Sample Send Product C++



The following code :
=====================

#include<iostream.h>
#include<conio.h>
class SendProduct{
private:
float weight;
char location;
public:
void input(){
cout<<"Input Weight:";cin>>weight;
cout<<"Input Location(A,B,C):";cin>>location;
}
void display(){
cout<<weight<<"\t\t"<<location<<"\t\t"<<payment()<<"$"<<endl;
}
  float payment(){
if(location=='A'||location=='a')
return (weight*35/65);
else if(location=='B'||location=='b')
return (weight*25/90);
else
return (weight*45/20);
}
/*float payment(){
float s;
switch(location){
case 'A':
case 'a': s=(weight*35/65);break;
case 'B':
case 'b':   s=(weight*25/90);break;
case 'C':
case 'c':   s=(weight*45/20);break;
default :
cout<<"Input Location only A,B,C other Invalide"<<endl;
}
return s;
}*/
SendProduct(){weight=90;location='B';}
SendProduct(float w,char l){
weight=w;
location=l;}
SendProduct(SendProduct&send){
weight=send.weight;
location=send.location;
}
float getweight(){
return weight;
}
};
void sort(SendProduct a[],int n){
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(a[i].payment()>a[j].payment()){
SendProduct t=a[i];a[i]=a[j];a[j]=t;
}
}
void sort1(SendProduct a[],int n){
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(a[i].getweight()>a[j].getweight()){
SendProduct t=a[i];a[i]=a[j];a[j]=t;
}
}
SendProduct *max(SendProduct a[],int n){
SendProduct *P;
P=&a[0];
for(int i=1;i<n;i++)
if(P->payment()<a[i].payment())
P=&a[i];
return P;
}
SendProduct *min(SendProduct a[],int n){
SendProduct *P1;
P1=&a[0];
for(int i=1;i<n;i++)
if(P1->payment()>a[i].payment())
P1=&a[i];
return P1;
}
void main(){
int n,i;
SendProduct a[5]={SendProduct(10,'A'),SendProduct(20,'B'),
SendProduct(30,'C'),SendProduct(40,'A'),SendProduct(50,'C')};
cout<<"============================================"<<endl;
cout<<"Initialization of Oject:\n";
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
for(i=0;i<5;i++)
a[i].display();
cout<<"============================================"<<endl;
SendProduct b[25],*p,*p1;
cout<<"Input Data from Keyboard"<<endl ;
cout<<"Input N Value:";cin>>n;
for(i=0;i<n;i++)
b[i].input();
cout<<"============================================"<<endl;
cout<<"Data Before sort:"<<endl;
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
for(i=0;i<n;i++)
b[i].display();
cout<<"============================================"<<endl;
cout<<"Data After sort Payment:"<<endl;
sort(b,n);
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
for(i=0;i<n;i++)
b[i].display();
cout<<"============================================"<<endl;
cout<<"Data After sort Weight:"<<endl;
sort1(b,n);
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
for(i=0;i<n;i++)
b[i].display();
cout<<"============================================"<<endl;
p=max(b,n);
cout<<"the Bigest Product:"<<endl;
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
p->display();
   cout<<"============================================"<<endl;
p1=min(b,n);
cout<<"the Smallest Product:"<<endl;
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
p1->display();
}

0 comments:

Post a Comment