daaaar

ITCproj

Jun 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. // ITCproj2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include<iostream>
  5. using namespace std;
  6.  
  7. void findAuthorsAndPaperDetails(char[], char[], char[], char[], char[]);
  8. int searchNamesIndex(char[],char[], int);
  9. int adjustIndexToStartOFRecord(char[], int);
  10.  
  11. int main()
  12. {
  13.     char authors_list[1000]="$Talha Dar,Ibrahim Ahmed$Asfand Yaar,Abdulrahman Ahsan";
  14.     char titles_list[1000]="$Paper 1 title$Paper 2 Title$Paper 3 Title";
  15.     char venue_list[1000]="$Venue1$Venue 2$Venue 3";
  16.     char details_list[1000]="$12.3,12,01,09,2000$45.6,45,02,09,2000$09.8,76,54,32,2000";
  17.     char name[50]={'\0'};
  18.     int choice=-1;
  19.  
  20.     cout<<"\nWelcome to reference manager MLA format."<<endl;
  21.     while(choice!=0)
  22.     {
  23.         cout<<"\nEnter Name of an author, ending with a fullstop. This will print the paper associated with this author and it's details. ";
  24.         cout<<"\nENTER NAME: ";
  25.         cin.getline(name, 50, '.');
  26.         findAuthorsAndPaperDetails(authors_list, titles_list, venue_list, details_list, name);
  27.         cout<<"Enter 1 if you'd like to continue searching for more authors and papers, or enter 0 to terminate program.";
  28.         cout<<"\nEnter Choice: ";
  29.         cin>>choice;
  30.     }
  31.  
  32.  
  33.    
  34.  
  35.     return 0;
  36. }
  37. void findAuthorsAndPaperDetails(char authors[], char titles[], char venues[], char details[], char nameToSearch[])  //so far this functions only finds and prints the names of the authors, if one of the two is found.
  38. {
  39.     int a=0, b=0, c=0;
  40.     int count=0;
  41.     int index=-1;
  42.     bool found=false;
  43.     while(found=false)
  44.     {
  45.         found=true;
  46.         if(authors[a]=='$'){count++;}
  47.         if(authors[a]==nameToSearch[0])
  48.         {
  49.            index=searchNamesIndex(authors, nameToSearch, a);
  50.            if(index==-1){found=false;}
  51.         }
  52.     }
  53.     cout<<endl;
  54.     for(int x=index; authors[index]!='\0'; x++)
  55.     {
  56.              cout<<authors[x];
  57.     }
  58.  
  59.  
  60. }
  61.  
  62. int searchNamesIndex(char authors[], char name[], int i)   //Once, first letter of input name==a letter in author's list, the process of matching the rest of the name to an authors name begins here.
  63. {
  64.     bool found=true;
  65.     int x=0;
  66.     int index=0;
  67.     for(int y=i; authors[y]!='\0' || authors[y]==',';y++)
  68.     {
  69.         if(authors[y]!=name[x]){return -1; found=false;}
  70.         x++;
  71.     }
  72.     if(authors[i-1]==',')
  73.     {
  74.            
  75.            index=adjustIndexToStartOFRecord(authors, i);
  76.     }
  77.     index=i;
  78.     return index;;
  79. }
  80. int adjustIndexToStartOFRecord(char data[], int i)   //If name found is the second of two names in the record, the index is adjusted to the start of first name.
  81. {
  82.     int x=0;
  83.     for(x=i; data[x]!='$'; x--)
  84.     {
  85.     }
  86.     return x+1;
  87. }
Add Comment
Please, Sign In to add comment