CSI 250L Lab 6 Solution, Spring 2012

American University of Science and Technology · Programming II Lab · 4 pages · Dr. Saeed Raheel · with solution

All CSI 250L files
CSI 250L Lab 6 Solution, Spring 2012, page 1

Stuck on a question? A tutor can walk you through it.

CSI 250L Lab 6 Solution, Spring 2012, page 2 CSI 250L Lab 6 Solution, Spring 2012, page 3 CSI 250L Lab 6 Solution, Spring 2012, page 4

More CSI 250L files

Show the text of this lab
check the book #include"sup.h" sup::sup(char*n,char*c,int i) { setid(i); setn(n); setc(c); } void sup::setn(char*n) { name=new char[strlen(n)+1]; strcpy(name,n); } void sup::setc(char*c) { country=new char[strlen(c)+1]; strcpy(country,c); } void sup::setid(int i) { id=(i>0)? i:0; } char*sup::getn()const{return name;} char*sup::getc()const{return country;} int sup::getid()const{return id;} sup::~sup() { delete[]name; name=0; delete[]country; country=0; } void sup::print()const { cout<<getid()<<"\t\t"<<getn()<<"\t\t"<<getc()<<endl; } #ifndef SUP_H #define SUP_H #include<iostream> #include<string> using namespace std; class sup{ private: char*name; char*country; int id; public: sup(char[]="",char[]="",int=0); void setn(char*); void setc(char*); void setid(int); char*getn()const; char*getc()const; int getid()const; void print()const; ~sup(); }; #endif #include "sup.h" int main() { int N; cout<<"Please enter the number of suppliers to create : "; cin>>N; sup* s = new sup[N]; int ID; char n[100]; char c[100]; for (int i=0;i<N;++i) { cout<<"Please enter the supplier's id : "; cin>>ID; cout<<"Please enter the supplier's name : "; cin>>n; cout<<"Please enter the supplier's country : "; cin>>c; s[i].setid(ID); s[i].setn(n); s[i].setc(c); } int choice; do { cout <<"\n1. Display the name of a supplier knowing his ID"<<endl; cout <<"2. List the information about all suppliers located in USA"<<endl; cout <<"3. Exit"<<endl; cin >> choice; switch(choice) { case 1: cout<<"Please enter an id :"; cin>>ID; for (int i=0;i<N;++i) if(s[i].getid()==ID) cout<<s[i].getn()<<endl; break; case 2: for (int i=0;i<N;++i) if(strcmp(s[i].getc(),"USA")==0) s[i].print(); break; case 3: break; } }while (choice>0 && choice<3); system("pause"); return 0; }