Write a C++ code which will display the following menu,
-------------
Menu
----------

-----------
1.Read a list of numbers.
2.Display list.
3.Save list to File.
4.Load list from file
5.Search for a given number in the list.
6.Reverse list.

7.Calculate the sum of the list.

8.Calculate the average of the list.

9.Find the largest number in the list.

10.Find the smallest number in the list.

11.Exit.

Hence the program will read the choice enter
ed from the keyboard and a
switch
statement will proceed according to the choice of the user
(described below)
. If the
choice is not valid an appropriate message should be displayed.
The program
should
return back to the main menu after the completion of any selection
and will only be terminated when the Exit Program is selected.
Choices 1 to 10 will call appropriate functions to do the following:

  1. Prompt the proper messages for the user to enter the
    number of integers to be
    entered and then the integer numbers should be entered in sequence and stored
    in an array of integers.
    .
    2.Display the list of
    integer numbers stored in the array. This option will only be
    executed if the array is not empty and it
    has been loaded with numbers either
    entered from the keyboard or loaded from a file.

3.Save theinteger numbers of the array in a text file.

4.Load the numbers from the file in the array.

5.The user will be prompted to enter an integer number to be searched in the array
and the function will search to find the given number in the array and respond
with a message
hether or not the number is found in the list, how many times
the number is repe
ated in the list and the position(s) where the number is found
in the list.

6.Reverse the order of the list.

7.Calculate the summation of the integer numbers of the list.

8.Calculate the average of the numbers in the list.
This function will use the function created in option 7 above and just divide the result returned from the
function of option 7 with the number of numbers in the list.

9.Find and display the largest number in the list and the position where the number
is located in the list
.
10.Find and display the smallest number in the list and the position where the
number is located in the list.

Recommended Answers

All 6 Replies

Yes, that's probably a homework assignment. And your question is?

how to start!!
I write this

#include <iostream>

using namespace std;

const int Arr_Size = 20;
int sum;

void display_nums(int fu_num_arr[Arr_Size], int dn_nums);
void get_nums(int ga_nums[Arr_Size], int& gn_nums);
void search_for_number(int ga_nums[Arr_Size], int&number);
void reverse_list(int ga_nums[Arr_Size]);
void calculate_average(int ga_nums[Arr_Size]);
void find_largest(int ga_nums[Arr_Size]);
void find_minimun(int ga_nums[Arr_Size]);

void get_nums(int ga_nums[Arr_Size], int& gn_nums)
{
    //This is the function which will be used to read the numbers in the array
    int ga_count;
    //The number of number to be entered in the array will be entered by the user numbers to be
    cout << "Enter the number of numbers to be entered:>>";
    cin >> gn_nums;
    //This is the loop which will read the numbers in the array
    for ( ga_count=0 ; ga_count < gn_nums; ga_count++ )
  {
    cout << "Enter number " << ga_count+1 << ":";
    cin >>  ga_nums[ga_count];

  }
    return;
}

void display_nums(int fu_num_arr[Arr_Size], int dn_nums)
{
    //This is the function which will be used to display the numbers of the array
    //on the screen

 int f_count;
 // this is the loop which will pass through the elements of the array and display them
 // on the screen
 for ( f_count=0 ; f_count < dn_nums ; f_count++ )
  {
    cout <<"Num " << f_count +1 <<": "<< fu_num_arr[f_count]<< endl;
  }
 system("Pause");
 return;
}

void search_for_number(int ga_nums[Arr_Size], int&number)
{
    int count;
    int counter;
    counter=0;
    //This is the function which will be used to search for a number
    //given by the user
cout << "Enter a number to search"<<endl;
cin>>number;
for (count=0,count<=Arr_Size,count++);
{
        if (ga_nums[count] == number) 
        {
            cout<<"The number is in the list at possition "<<count <<endl;
            counter++;
            count++;
        }

        else {
            count++;
        }

 if (counter>0) 
 {
    cout<<"The number is found "<<counter<<" times in the list"<<endl;
    }
    return;
}
////////////////////////////////////////////
void reverse_list(int ga_nums[Arr_Size]);
{
    int temp[Arr_Size];
    int count;

for (count=Arr_Size-1; count>=0; count++)
    {
        temp[count]=ga_nums[count];
        count++;
}
for (count=0; count>=Arr_Size-1; count++)
    ga_nums[Arr_Size]=temp[count];

return;
}

void calculate_sum(int ga_nums[Arr_Size]);
    {
        int sum;
        int count;
    for (count=0; count>=Arr_Size; count++)
    {
        sum+=ga_nums[count];
        cout<<"Sum = "<<sum<<endl;
    }
    return;
}

void calculate_average(int ga_nums[Arr_Size]);
{
    int average;
    sum=(calculate_sum(ga_nums));
    average=sum/Arr_Size;
    return;
}

void find_largest(int ga_nums[Arr_Size]);
{
    int count;
    int max;
    int possition;
    max=ga_nums[0];
    possition=0;

    for (count=1; count<Arr_Size; count++)
    {
        if (ga_nums[count]>max)
        {
            max=ga_nums[count];
            possition=count;
        }
    }
    return;
}

void find_minimun(int ga_nums[Arr_Size]);
{
    int count;
    int min;
    int max;
    int possition;
    min=ga_nums[0];
    possition=0;

    for (count=1; count<Arr_Size; count++)
    {
        if (ga_nums[count]<min)
        {
            max=ga_nums[count];
            possition=count;
        }
    }
    return;
}






void Display_Menu();
{
    // This is the function of the menu to be displayed to the user
int choice;
int sum;
int Arr_MyNums [Arr_Size];
int nums, count, result=0;
int number;
bool flist = false; // This will be set to true if option 1 was previously 
                    // selected and the array is not empty.
bool addlist=false; // This will be set to true if option 7 was previously 
                    // selected and the programm has already done the addition.

//The menu will be displayed on the screen every time a selection of the user is completed 
// until the user selects the EXIT option
do
    {
    system("CLS"); // This will clear the screen every time we reurn back to the main menu.

    cout<<"-----------------MENU----------------"<<endl;
    cout<<"1.Read a list"<<endl;
    cout<<"2.Display the list"<<endl;
    cout<<"3.Save the list to file"<<endl;
    cout<<"4.Load list from file"<<endl;
    cout<<"5.Search for a given number in the list"<<endl;
    cout<<"6.Reverse list"<<endl;
    cout<<"7.Calculate the sum of the list"<<endl;
    cout<<"8.Calculate the average of the list"<<endl;
    cout<<"9.Find the largest number in the list"<<endl;
    cout<<"10.Find the smallest number in the list"<<endl;
    cout<<"11.Exit"<<endl; 
    cout << "Please select "<< " >> " ;
    cin >> choice;

    // The following switch is based on the selection of the user and the appropriate function 
    // will be called

    switch (choice)
        {
        case 1 :    flist = true;

                    get_nums( Arr_MyNums, nums); 

                    break;   

                    //////////////////////////////
        case 2 :    if (flist)
                    {
                        display_nums(Arr_MyNums, nums);
                    }
                    else 
                        {
                            cout << "The list is empty"<< endl;
                            system("Pause");
                        }   
                    break; 

                    ///////////////////
        /*case 3 : ... break; 
        case 4 : .... break;*/
        case 5: if (flist){
                    search_for_number(Arr_MyNums,number);
                }
                else
                {
                    cout << "The list is empty"<< endl;
                            system("Pause");
                        }   break; 
            /////////////////////////
        case 6: if (flist){
                    reverse_list(Arr_MyNums);
                }
                else
                    {
                    cout << "The list is empty"<< endl;
                            system("Pause");
                        }   break; 

            ////////////////////////////////////////
        case 7: addlist=true;
            if (flist){
                    calculate_sum(Arr_MyNums);
            }
            else
                    {
                    cout << "The list is empty"<< endl;
                            system("Pause");
                        }   
            break; 
            /////////////////////////////////////

        case 8: if ((flist) && (addlist))
                {
                    calculate_average (Arr_MyNums-sum);
                }
                else
                    {
                    cout << "The list is empty or the programm hasnt calculate the sum yet (Select 1 , or 7)"<< endl;
                            system("Pause");
                        }   

                break; 

        case 9: if (flist)
                {
                    find_largest(Arr_MyNums);
                }

    else
                    {
                    cout << "The list is empty "<< endl;
                            system("Pause");
                        }   
                break; 
                //////////////////////

    case 10: if (flist)
                {
                    find_minimun(Arr_MyNums);
             }

    else
                    {
                    cout << "The list is empty "<< endl;
                            system("Pause");
                        }   
             break;
             ///////////////////////////////
    case 11: system("pause");
        break;

        default: cout << "INVALID CHOICE, PLEASE ENTER A VALID CHOICE!!!" << endl;

            break; 
        }
    }
while (choice != 11);
}

//____________________________________________
int main ();
{
    // This is the main function of the program


  Display_Menu();


  return;
  system("pause");
}

how to start!!

Sir, believe me, we all want to help here.
But we just need a decent question about your problem. "how to start!! hardly qualifies as a question.

i have this error

Error 1 error C1075: end of file found before the left brace '{' at 'c:\users\user\desktop\assigment xristougenna\exercise 1\exercise 1\exercise 1.cpp(52)' was matched c:\users\user\desktop\assigment xristougenna\exercise 1\exercise 1\exercise 1.cpp 312 1 Exercise 1

Ahaa! Now we are getting somewhere!
I guess, in the function void search_for_number a for statement on line 58, is missing an ending brace '}'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.