Aug 5, 2009 at 9:31am UTC
I got a problem with a program for Port Cargo Retrieval question.
I need to create a 10 x 10 stack , 10 companies, 1 stack for 1 company. and would be able to take out the particular cargo when chosen.
This problem must be solved by using class stack.
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
template<typename T>
void printstack(T &x)
{
while(!x.empty())
{
cout<<x.top()<<" ";
x.pop();
}
}
class mycargo{
public:
string name;
string items;
string weight;
};
int main(){
stack<mycargo>coyA;
stack<mycargo>coyB;
stack<mycargo>coyC;
stack<mycargo>coyD;
stack<mycargo>coyE;
stack<mycargo>coyF;
stack<mycargo>coyG;
stack<mycargo>coyH;
stack<mycargo>coyI;
stack<mycargo>coyJ;
stack<mycargo>tempco;
stack<string>tempstack;
mycargo temp;
mycargo temp2;
mycargo temp3;
mycargo temp4;
mycargo temp5;
mycargo C1;
mycargo C2;
mycargo C3;
mycargo C4;
mycargo C5;
mycargo C6;
mycargo C7;
mycargo C8;
mycargo C9;
mycargo C10;
C1.name = "Tan";
C1.items= "apparel";
C1.weight= "100 tonnes";
C2.name = "Wong";
C2.items= "watches";
C2.weight= "75 tonnes";
C3.name = "Lim";
C3.items= "food";
C3.weight= "55 tonnes";
C4.name = "Chua";
C4.items= "clothes";
C4.weight= "25 tonnes";
C5.name = "hilton";
C5.items= "drinks";
C5.weight= "30 tonnes";
coyA.push(C4);
coyA.push(C3);
coyA.push(C2);
coyA.push(C1);
string company,name_temp;
cout<<"company: ";
cin>>company;
if(company=="coyA"){
cout<<"Name of container: ";
cin>>name_temp;
temp=coyA.top();
tempstack.push(name_temp);
cout<<tempstack.top();
if(name_temp==tempstack.top()){
tempco.push(coyA.top());
cout<<temp.name;
cout<<temp.items;
cout<<temp.weight;
coyA.pop();
}
}
/*while(!coyA.empty()){
temp=coyA.top();
cout<<temp.name<<endl;
cout<<temp.items<<endl;
cout<<temp.weight;
coyA.pop();
}*/
}
no idea hw to continue
Aug 5, 2009 at 9:51am UTC
You really should post your question in one forum.
If you enter the values coyA and Tan when prompted, it prints your output. So it works, right?
Aug 5, 2009 at 9:55am UTC
well, it does print. But, it prints no matter what input i type for name_temp. so,
name_temp==tempstack.top() doesn't really compare at all.