Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <iostream>
#include<cstdlib>
#include<fstream>
using namespace std;


int Qclothes,Qshoes,Qtoiletries,Qgadget,temp;
class MySuitcase
{
public:
int quantity; //declaration of data members
char colour;
double weight;
char sizeA; //size for clothes s,m,l,xl
int size2; //size for shoes (4-10)
int i,j;

MySuitcase() //constructor with no argument
{
char white,s;
quantity=0;
weight = 0;
colour=white;
sizeA=s;
size2=4;
}

double total_weight(double v,double w,double x,double y,double z)
{
double total_weight;
total_weight=v+w+x+y+z; //function to calculate the total weight of items
return total_weight;
}


};
void printArray(int arr[], int size) {
for ( int p = 0; p < size; p++ ) {
cout << arr[p] << ' ';
}
cout << endl;
}

void swap_item(int MySuitcase[],int &i, int &j)
{ int temp = 0;
temp = MySuitcase[i] ;
MySuitcase[i] = MySuitcase[j];
MySuitcase[j] = temp;
}
int main() //main function
{
MySuitcase[4]= {Qtoiletries,Qclothes,Qshoes,Qgadget};
int a,b,c,d,press; //quantity
double v,w,x,y,z,t;
int printArray;//weight

cout<<"Please enter the things you want to bring in suitcase:" <<endl;
cout<<"\n";

cout<<"=========Toiletries========="<<endl; //object 1
cout<<"Quantity of your toiletries: "<<"\t"; //properties
cin>>a;
cout<<"Your quantity:"<<"\t"<<a<<endl;
cout<<"\n";
cout<<"What is the weight of your toiletries(in kg):"<<"\t";
cin>>v;
cout<<"Your weight:"<<"\t"<<v<<"kg"<<endl;

cout<<"\n";
cout<<"=======Formal clothes=======:"<<endl; //object 2
cout<<"Quantity of your formal clothes: "<<"\t"; //properties
cin>>b;
cout<<"\n";
cout<<"What is the weight of your formal clothes(in kg) :"<<"\t";
cin>>w;
cout<<"Your weight:"<<"\t"<<w<<"kg"<<endl;

cout<<"\n";
cout<<"=======Gadgets======="<<endl; //object 3
cout<<"How many gadget you bring: "<<"\t"; //properties
cin>>c;
cout<<"Your gadget quantity is:"<<"\t"<<c<<endl;
cout<<"\n";
cout<<"What is your gadget weight(in kg):"<<"\t";
cin>>x;
cout<<"Your weight:"<<"\t"<<x<<"kg"<<endl;

cout<<"\n";

cout<<"========Shoes========="<<endl; //object 4
cout<<"Quantity of your shoes: "<<"\t"; //properties
cin>>d;
cout<<"Your quantity:"<<"\t"<<d<<endl;
cout<<"\n";
cout<<"What is the weight of your shoes (in kg):"<<"\t";
cin>>y;
cout<<"Your weight:"<<"\t"<<y<<"kg"<<endl;

cout<<"\n";

cout<<"Your total weight in your suitcase is:"<<"\t"<<MySuitcase().total_weight(v, w, x, y, z)<<"kg"<<endl;
//total weight of all items
cout<<"\n";
if(MySuitcase().total_weight(v, w, x, y, z)<=30) //if-else statement(selection structure)
{ //to state whether user have exceed 30kg or not
cout<<"You have not exceed the maximum limit of your suitcase"<<endl;
}
else
{
cout<<"Your suitcase have exceeded the maximum weight!"<<endl;
}

cout << " Please input the things that you want to swap: ";


cout << "The original array is:\t";
printArray(arr, 4);

swap_item(arr, 0, 1);
cout << "The swapped array is:\t";
printArray(arr, 4);




system("PAUSE");
return 0;
}
Posted
Comments
[no name] 19-Mar-14 23:57pm    
Not a question yet - needs some explanation. Rather than dumping code just give a clear example.
Sergey Alexandrovich Kryukov 20-Mar-14 0:10am    
Not clear what do you mean by "swapping" of arrays, and why. This is nothing but code dump. Unformatted code, that's why you have
#include
#include
#include
(look at you own code yourself).
—SA
Member 10661589 20-Mar-14 1:16am    
Im sorry, it was suppose to be #include < iostream >
#include < cstdlib > and #include <fstream>
How do I swap the object which is Qtoiletries,Qclothes,Qgadget and Qshoes?I have to swap them using array.I don't know how..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900