Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modular Design: ***please Help me to Fix may main menu** fixing my main() to usi

ID: 3721845 • Letter: M

Question

Modular Design:

***please Help me to Fix may main menu**

fixing my main() to using functions. there should at least be a couple of functions here to process the ProgrammingProject object.

int main()
{
    //    declare a variable of type linked list
    LinkedList myList;

    //    declare other variables
    char choice;
    char n;

    //    let the user know about the program
    cout << " A program to demonstrate LinkedList class.";

    //    print a list of choices to the user
    do {
        cout<<" MENU ";
        cout << " Append a node : A";
        cout << " Insert a node : I";
        cout<<" Insert a node At : P";
        cout << " Delete a node : D";
        cout<<" Remove node At : T";
        cout<<" Search a node : S";
          cout<< " Reverse nodes    : R";
        cout << " Quit          : Q";

        //    prompt and read the user's choice.
        cout << " Enter your choice: ";
        cin >> choice;

        //do appropriate action basing on choice selected.
        switch ( choice )
        {
            case 'A' :
            case 'a' :
                    //    prompt and read an character.
                        cout<<" Enter an character: ";
                        cin >> n;

                    //    append the number into list.
                        myList.appendNode( n );
                        break;

            case 'I' :
            case 'i' :
                    //    prompt and read an character.
                        cout<<" Enter an character: ";
                        cin >> n;

                    //    insert the number into list.
                        myList.insertNode( n );
                        break;

            case 'D' :
            case 'd' :
                    //    prompt and read an character.
                    cout <<" Enter an character : ";
                        cin >> n;

                    //    delete the number from list.
                        myList.deleteNode( n );
                        break;
                  case 'R':
                    
            case 'r': //Reversing nodes of list.
                       myList.Reverse();
                       break;
            case 'T':
            case 't':    int pos;
                       //prompt a character to search.
                cout<<" Enter element position to be deleted:";
                       cin>>pos;
                       myList.deleteAt(pos);
                       break;

            case 'S':
            case 's':   int position;
                       //prompt a character to search.
                       cout<<"Enter element to be searched:";
                       cin>>n;
                       //Search element.
                       position=myList.Search(n);
                       if(position ==-1)
                cout<<" Element not found in the list"<<endl;
                       else
                   cout<<" Element found at:"<<position<<endl;
                       break;
            case 'P':
            case 'p': int Loc;
                      //    prompt and read an character.
                        cout<<" Enter an character: ";
                        cin >> n;
                        //prompt a integer to search.
                      cout<<" Enter position to be inserted:";
                       cin>>Loc;
                       myList.insertNodeAt(n,Loc);
                       break;
                    
            case 'Q' :
            case 'q' :
                        choice = 'q';
        }    //    end switch

    } while ( choice != 'q' );    //    end do-while

    return 0;    // indicate program executed successfully
}            // end of function, ma

Explanation / Answer

/* I think this main() function does not have any problem andis s going to work with fucntions specified provided with implementation */

int main()
{
// declare a variable of type linked list
LinkedList myList;
// declare other variables
char choice;
char n;
// let the user know about the program
cout << " A program to demonstrate LinkedList class.";
// print a list of choices to the user
do {
cout<<" MENU ";
cout << " Append a node : A";
cout << " Insert a node : I";
cout<<" Insert a node At : P";
cout << " Delete a node : D";
cout<<" Remove node At : T";
cout<<" Search a node : S";
cout<< " Reverse nodes : R";
cout << " Quit : Q";
// prompt and read the user's choice.
cout << " Enter your choice: ";
cin >> choice;
//do appropriate action basing on choice selected.
switch ( choice )
{
case 'A' :
case 'a' :
// prompt and read an character.
cout<<" Enter an character: ";
cin >> n;

// append the number into list.
myList.appendNode( n );
break;
case 'I' :
case 'i' :
// prompt and read an character.
cout<<" Enter an character: ";
cin >> n;

// insert the number into list.
myList.insertNode( n );
break;
case 'D' :
case 'd' :
// prompt and read an character.
cout <<" Enter an character : ";
cin >> n;

// delete the number from list.
myList.deleteNode( n );
break;
case 'R':
  
case 'r': //Reversing nodes of list.
myList.Reverse();
break;
case 'T':
case 't': int pos;
//prompt a character to search.
   cout<<" Enter element position to be deleted:";
cin>>pos;
myList.deleteAt(pos);
break;
case 'S':
case 's': int position;
//prompt a character to search.
cout<<"Enter element to be searched:";
cin>>n;
//Search element.
position=myList.Search(n);
if(position ==-1)
cout<<" Element not found in the list"<<endl;
else
cout<<" Element found at:"<<position<<endl;
break;
case 'P':
case 'p': int Loc;
// prompt and read an character.
cout<<" Enter an character: ";
cin >> n;
//prompt a integer to search.
cout<<" Enter position to be inserted:";
cin>>Loc;
myList.insertNodeAt(n,Loc);
break;
  
case 'Q' :
case 'q' :
choice = 'q';
} // end switch
} while ( choice != 'q' ); // end do-while
return 0; // indicate program executed successfully
} // end of function, main[]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote