Expand|Select|Wrap|Line Numbers
- #include<iostream>
- using namespace std;
- struct User{
- string read;
- string write;
- string execute;
- };
- struct File
- {
- string filename;
- User accessrights;
- File*next;
- };
- bool isEmpty(File *head);
- char menu();
- void insertAsFirstElement(File *&head, File *&last, string filename, User accessrights);
- void insert(File *&head, File *&last, string filename, User accessrights);
- void remove(File *&head, File *&last);
- void showList(File *current);
- bool isEmpty(File *head)
- {
- if(head == NULL)
- return true;
- else
- return false;
- }
- char menu()
- {
- char choice;
- cout<<"Menu\n";
- cout<<"1.Add an item \n";
- cout<<"2.Remove an item \n";
- cout<<"3.Show the list \n";
- cout<<"4.Exit \n";
- cin>>choice;
- return choice;
- }
- void insertAsFirstElement(File *&head, File *&last, string filename1, User accessrights1)
- {
- File *temp = new File;
- temp->filename = filename1;
- temp->accessrights=accessrights1;
- temp -> next = NULL;
- head = temp;
- last = temp;
- }
- void insert(File *&head, File *&last, string filename2, User accessrights2)
- {
- if(isEmpty(head))
- {
- insertAsFirstElement(head, last, filename2, accessrights2);
- }
- else
- {
- File* temp = new File;
- temp -> filename = filename2;
- temp -> accessrights=accessrights2;
- temp -> next = NULL;
- last->next =temp;
- last = temp;
- }
- }
- void remove(File *&head, File *&last)
- {
- if(isEmpty(head))
- cout<<"The list is alreay empty.\n";
- else if(head==last)
- {
- delete head;
- head==NULL;
- last = NULL;
- } else
- {
- File*temp = head;
- head = head->next;
- delete temp;
- }
- }
- void showList(File *current)
- {
- if(isEmpty(current))
- {
- cout<<"The list is Empty\n";
- }
- else
- {
- cout<<"The list contains : \n";
- while(current !=NULL)
- {
- cout<<current->filename<<endl;
- cout<<current->accessrights.read<<current->accessrights.write<<current->accessrights.execute;
- cout<<"--------------------"<<endl;
- current = current ->next;
- }
- }
- }
- int main()
- {
- File *head = NULL;
- File*last = NULL;
- char choice;
- string filenamE;
- User accessrightS;
- do{
- choice = menu();
- switch(choice)
- {
- cout<<"Enter your choice :";
- cin>>choice;
- case '1' : cout<<"Enter file name :";
- cin>>filenamE;
- cout<<"Grant Access rights :";
- cin>>User.read>>User.write>>User.execute;
- insert(head, last, filenamE, accessrightS);
- break;
- case '2' : remove(head,last);
- break;
- case '3' : showList(head);
- break;
- default: cout <<cout<<"System exit\n";
- }
- }while(choice!='4');
- }
I have mistake in the line in Case 1 where I need to get three inputs from the user.
cout<<"Grant Access rights :";
cin>>User.read>>User.write>>User.execute;
insert(head, last, filenamE, accessrightS);
I get the error
------------------
D:\SEMESTER_F\FavQuotes\Source & Exe\FMSFinal.cpp In function 'int main()':
137 19 D:\SEMESTER_F\FavQuotes\Source & Exe\FMSFinal.cpp [Error] expected primary-expression before '.' token
137 30 D:\SEMESTER_F\FavQuotes\Source & Exe\FMSFinal.cpp [Error] expected primary-expression before '.' token
137 42 D:\SEMESTER_F\FavQuotes\Source & Exe\FMSFinal.cpp [Error] expected primary-expression before '.' token