KeeganT

Ass68

Oct 15th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string names[13]{"Ageloff","Anderson","Biegel","Biow","Bisland","Arnott","Arnston","Ault","Avison","Bard","Bowman","Adams","Adrian"};
  8.     for(int c=0;c<13;c++)cout<<names[c]<<", ";
  9.     string alist="", blist="", temp="";
  10.     for(int c=0;c<13;c++)
  11.     {
  12.         temp=names[c];
  13.         if(temp[0]=='A')
  14.         {
  15.             alist+=temp;
  16.             alist+=", ";
  17.         }
  18.     }
  19.     cout<<"\nNames beginning with A: "<<alist;
  20.     for(int c=0;c<13;c++)
  21.     {
  22.         temp=names[c];
  23.         if(temp[0]=='B')
  24.             {
  25.                blist+=temp;
  26.                blist+=", ";
  27.             }
  28.     }
  29.     cout<<"\nNames beginning with B: "<<blist<<endl;
  30.     string nameSearch;
  31.     cout<<"Enter a name to be searched for: ";
  32.     cin>>nameSearch;
  33.     for(int c=0;c<13;c++)
  34.     {
  35.         temp=names[c];
  36.         if(temp==nameSearch)
  37.         {
  38.             cout<<temp<<" was found at position "<<c+1<<endl;
  39.             break;
  40.         }
  41.         else if(temp!=nameSearch&&c>11)cout<<"Name not found!"<<endl;
  42.     }
  43.     string strSearch;
  44.     cout<<"Enter a search string: ";
  45.     cin>>strSearch;
  46.     bool isFound=false;
  47.     for(int c=0;c<13;c++)
  48.     {
  49.         int num=names[c].find(strSearch);
  50.         if(num!=-1)
  51.         {
  52.             cout<<names[c]<<", ";
  53.             isFound=true;
  54.         }
  55.     }
  56.     if(isFound==false)cout<<"Search string not found!";
  57.     cout<<"\nNames in descending order"<<endl;
  58.     string hold="";
  59.     for(int c=0;c<13;c++)
  60.     {
  61.         for(int x=0;x<13;x++)if(names[x]<names[x+1])
  62.         {
  63.             hold=names[x];
  64.             names[x]=names[x+1];
  65.             names[x+1]=hold;
  66.         }
  67.     }
  68.     for(int c=0;c<13;c++)cout<<names[c]<<", ";
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment