Question: ****in C++ menu driven program (calling functions)**** could you help me to fix main menu to make shorter and use some funcation that link to

****in C++ menu driven program (calling functions)****

could you help me to fix main menu to make shorter and use some funcation that link to linklist for that, for example : in below one program that use function I need something like that :

*******************************************************************************************

#include  #include  using namespace std; //Functions void showWelcome(); void showMenu(); int showSpring(); int showSummer(); int showFall(); int showWinter(); int main() { int choice; //menu choice //constants for menu choices const int SPRING_CHOICE = 1, SUMMER_CHOICE = 2, FALL_CHOICE = 3, WINTER_CHOICE = 4, QUIT_CHOICE = 5; cout << fixed << showpoint << setprecision(1); //sets to 1 decimal place do { showWelcome(); // Show Welcome screen showMenu(); // Display Menu cin >> choice; //Validate menu selection while (choice < SPRING_CHOICE || choice > QUIT_CHOICE) { cout << "Please enter a valid menu choice: "; cin >> choice; } //If user does not want to quit, proceed. if (choice != QUIT_CHOICE) { switch (choice) { case SPRING_CHOICE: int showSpring(); break; case SUMMER_CHOICE: int showSummer(); break; case FALL_CHOICE: int showFall(); break; case WINTER_CHOICE: int showWinter(); break; } } } while (choice != QUIT_CHOICE); return 0; } //Welcome Function void showWelcome() { cout << "Welcome to the average rainfall calculator" << endl << endl; system ("pause"); } //Menu Function void showMenu() { cout << "Please choose a season" << endl << endl << "1. Spring" << endl << "2. Summer" << endl << "3. Fall" << endl << "4. Winter"<< endl << "5. Quit" << endl << endl; } //Spring choice function int showSpring(float spring, float spring1, float spring2, float spring3) { cout << "Enter the rainfall for month one " << endl; cin >> spring1; cout << endl << "Enter the rainfall for month two " << endl; cin >> spring2; cout << endl << "Enter the rainfall for month three " << endl; cin >> spring3; spring = (spring1 + spring2 + spring3) / 3; cout << endl << "The average rainfall for Spring was " << spring << endl << endl; return 0; } //Summer choice function int showSummer(float summer, float summer1, float summer2, float summer3) { cout << endl << "Enter the rainfall for month one " << endl; cin >> summer1; cout << endl << "Enter the rainfall for month two " << endl; cin >> summer2; cout << endl << "Enter the rainfall for month three " << endl; cin >> summer3; summer = (summer1 + summer2 + summer3) / 3; cout << endl << "The the average rainfall for Summer was " << summer << endl << endl; return 0; } //Fall choice function int showFall(float fall, float fall1, float fall2, float fall3) { cout << endl << "Enter the rainfall for month one " << endl; cin >> fall1; cout << endl << "Enter the rainfall for month two " << endl; cin >> fall2; cout << endl << "Enter the rainfall for month three " << endl; cin >> fall3; fall = (fall1 + fall2 + fall3) / 3; cout << endl << "The average rainfall for Fall was " << fall << endl << endl; return 0; } //Winter choice function int showWinter(float winter, float winter1, float winter2, float winter3) { cout << endl << "Enter the rainfall for month one " << endl; cin >> winter1; cout << endl << "Enter the rainfall for month two " << endl; cin >> winter2; cout << endl << "Enter the rainfall for month three " << endl; cin >> winter3; winter = (winter1 + winter2 +winter3) / 3; cout << endl << "The average rainfall for Winter was " << winter << endl << endl; return 0; }

*************************************************************************

(-5) main() does not use functions. I understand there is not a lot of code in main() because of the way you (wrongly) structured your input validation but there should at least be a couple of functions here to process the ProgrammingProject object.

#include

#include "CharacterList.h"

#include

using namespace std;

int main()

{

int choice, position, i;

char value;

bool isValid = false;

CharacterList list;

while (1)

{

cout << "Welcome to the List..Choose from Below: " << endl;

cout << "1.Append a Node to the list " << endl;

cout << "2.Insert a Node at a position" << endl;

cout << "3.Delete a Node at a position" << endl;

cout << "4.Search a Value" << endl;

cout << "5.Print Linked List" << endl;

cout << "6.Reverse Linked List " << endl;

cout << "7.Exit " << endl;

cout << "Enter your choice : ";

cin >> choice;

switch (choice)

{

case 1:

cout << "Enter Character to append: " << endl;

cin >> value;

isValid = false;

do {

if (isalpha(value) && isupper(value))

isValid = true;

else {

cout << "Entered value is invalid..Please enter a valid UpperCase character." << endl;

cin >> value;

}

} while (!isValid);

list.appendNode(value);

cout << "Done" << endl;

cout << endl;

break;

case 2:

cout << "Enter Character to insert:" << endl;

cin >> value;

isValid = false;

do {

if (isalpha(value) && isupper(value))

isValid = true;

else {

cout << "Entered value is invalid..Please enter a valid UpperCase character." << endl;

cin >> value;

}

} while (!isValid);

cout << "Enter Character to insert:" << endl;

cin >> position;

i = list.insertNode(value, position);

if (i == -1)

cout << "Position is Invalid.";

else

cout << "Done" << endl;

cout << endl;

break;

case 3:

cout << "Enter Position to delete:" << endl;

cin >> position;

i = list.deleteNode(position);

if (i == -1)

cout << "Position is Invalid.";

else

cout << "Done" << endl;

cout << endl;

break;

case 4:

cout << "Enter Character to Search:" << endl;

cin >> value;

isValid = false;

do {

if (isalpha(value) && isupper(value))

isValid = true;

else {

cout << "Entered value is invalid..Please enter a valid UpperCase character." << endl;

cin >> value;

}

} while (!isValid);

position = list.search(value);

if (position == -1)

cout << value << " not found in the list" << endl;

else

cout << value << " found at position " << position + 1 << endl;

cout << endl;

break;

case 5:

list.printList();

cout << endl;

break;

case 6:

list.reverse();

cout << "Done";

cout << endl;

break;

case 7:

cout << "Exiting..." << endl;

exit(1);

break;

default:

cout << "Invalid choice." << endl;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!