Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Applephn::display(string name)
- {
- fstream fin;
- fin.open("Applephn.csv",ios::in);
- vector<string>row;
- string line,word,temp;
- int cnt=0;
- while(getline(fin,line))
- {
- row.clear();
- //getline(fin,line);
- stringstream s(line);
- while(getline(s,word,','))
- {
- row.push_back(word);
- }
- if(name==row[0]){
- cnt=1;
- cout<<"Brand: "<<row[0]<<endl;
- cout<<"Battery : "<<row[1]<<endl;
- cout<<"Price: "<<row[2]<<endl;
- }
- }
- fin.close();
- if(cnt==0)
- {
- cout<<"Not found"<<endl;
- }
- }
- void Applephn::compare(string name1,string name2)
- {
- fstream fin;
- fin.open("Applephn.csv",ios::in);
- vector<string>row;
- vector<string>phn1,phn2;
- string line,word,temp;
- int cnt1=0,cnt2=0;
- while(getline(fin,line))
- {
- row.clear();
- //getline(fin,line);
- stringstream s(line);
- while(getline(s,word,','))
- {
- row.push_back(word);
- }
- if(name1==row[0]){
- cnt1=1;
- phn1=row;
- }
- else if(name2==row[0])
- {
- cnt2=1;
- phn2=row;
- }
- }
- fin.close();
- if(cnt1==1 && cnt2==1)
- {
- for(int i=0;i<phn1.size();i++)
- {
- cout<<phn1[i]<<" "<<phn2[i]<<endl;
- }
- }
- else if(cnt1==0)
- {
- cout<<"Sorry"<<endl;
- cout<<"Model "<<name1<<"is not available"<<endl;
- }
- else if(cnt2==0)
- {
- cout<<"Sorry"<<endl;
- cout<<"Model "<<name2<<"is not available"<<endl;
- }
- else
- {
- cout<<"Sorry"<<endl;
- cout<<"Both Model are not available"<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement