[ create a new paste ] login | about

Link: http://codepad.org/FygNuYo9    [ raw code | output | fork ]

C++, pasted on Sep 15:
#include <iostream>
using namespace std;
 
void Task(int a[], int &size)
{
    int n=0;
 
    while(n!=4)
    {
        cout << "Choose Option" << endl;
        cout << "0 Print the array of grades" << endl;
        cout << "1 Find the minimum grade" << endl;
        cout << "2 Find the maximum grade" << endl;
        cout << "3 Print the average on all tests for each student" << endl;
        cout << "4 End program" << endl;
        cout<<"Enter Option: ";
        cin >> n;
 
        if (n == 0)
        {
            cout<<"All grades are: ";
            for (int i = 0; i < size; i++)
            {
                cout << a[i] << " ";
            }
            cout<<endl;
        }
 
        if (n == 1)
 
        {
            cout<<"Minimum Grade is: ";
            int min = a[0];
            for (int i = 0; i < size; i++)
            {
                if (a[i] < min)
                    
                min = a[i];
            }
            cout << min << endl;
        }
        if (n == 2)
        {
            cout<<"Maximum Grade is: ";
            int max = a[0];
            for (int i = 0; i < size; i++)
            {
                if (a[i] > max)
 
                    max = a[i];
            }
            cout << max << endl;
        }
 
        if (n == 3)
        {
            cout<<"Average Grade is: ";
            float sum = 0;
            for (int i = 0; i < size; i++)
            {
                sum += a[i];
            }
 
            cout << (sum / size) << endl;
        }
 
    } 
    cout<<"Program Exited";
}
 
int main()
{
    int size, n;
    cout << "Enter size of array ";
    cin >> size;
    int *a = new int[size]; //Dynamically allocating array
    for (int i = 0; i < size; i++)
    {
        cin >> a[i];
    }
 
    Task(a, size);
 
    delete []a;
 
    return 0;
}


Output:
1
2
Enter size of array std::bad_alloc: St9bad_alloc
Aborted.


Create a new paste based on this one


Comments: