Question

In: Computer Science

Directions: Write a C++ program that will create an array of four integers. It will allow...

Directions:

Write a C++ program that will create an array of four integers.

It will allow the user to enter in four valid scores and store them in the array. ( valid range is 0 - 100)

It will compute the letter grade based upon the four scores, namely, A = 90 - 100, B= 80- 89, C = 70-79, D = 60-69, otherwise F.

It will display the scores and letter grade to the screen.

NOTE: No menu is required.

2. Write a function called inputData that takes in a pointer to the array of integers as a parameter, prompts the user for four valid score values and stores these values in the array of integers. (15 points).

4. Write a function called calcGrade that takes in a pointer to the array of integers as a parameter, computes and returns the letter grade based upon the scale listed above. (15 points).

5. Write a function called displayResults that takes in a pointer to the array of integers and the character letter grade as a parameters, computes, and displays these values in the format shown in the sample run below. (15 points).

6. Add comments wherever necessary. (5 points)

Sample Runs:

NOTE: not all possible runs are shown below.

Run 1:

Welcome to the compute letter grade program
Test score 1: Please enter in a score...-9
Please enter in a score (0-100)...999
Please enter in a score (0-100)...90
Test score 2: Please enter in a score...98
Test score 3: Please enter in a score...96
Test score 4: Please enter in a score...95
Test 1: 90
Test 2: 98
Test 3: 96
Test 4: 95
Grade : A

Run 2:

Welcome to the compute letter grade program
Test score 1: Please enter in a score...90
Test score 2: Please enter in a score...70
Test score 3: Please enter in a score...85
Test score 4: Please enter in a score...76
Test 1: 90
Test 2: 70
Test 3: 85
Test 4: 76
Grade : B

General Requirements:

1) Include the header comment with your name and other information on the top of your files.

2. Please make sure that you're conforming to specications (program name, print statements, expected inputs and outputs etc.). Not doing so will result in a loss of points. This is especially important for prompts. They should match mine EXACTLY.

3. If we have listed a specication and allocated point for it, you will lose points if that particular item is missing from your code, even if it is trivial.

4. No global variables (variables outside of main() ) unless they are constants.

5. All input and output must be done with streams, using the library iostream

6. You may only use the iostream and iomanip libraries. Including unnecessary libraries will result in a loss of points.

7. NO C style printing is permitted. (Aka, don't use printf). Use cout if you need to print to the screen.

8. When you write source code, it should be readable and well-documented (comments).

9. Make sure you either develop with or test with CLion (to be sure it reports no compile errors or warnings!) before you submit the program.

Solutions

Expert Solution

// do comment if any problem arises

// code

#include <iostream>

using namespace std;

// this function reads valid scores in given array

void inputData(int *scores)

{

    for (int i = 0; i < 4; i++)

    {

        // read ith score

        cout << "Test score " << i + 1 << ": Please enter in a score...";

        cin >> scores[i];

        // check for valid scores

        while (scores[i] < 0 || scores[i] > 100)

        {

            cout << "Please enter in a score (0-100)...";

            cin >> scores[i];

        }

    }

}

char calcGrade(int *scores)

{

    // total score

    float score = 0;

    // compute total score

    for (int i = 0; i < 4; i++)

        score += scores[i];

    // compute average

    score /= 4;

    // check for grade

    if (score >= 90)

        return 'A';

    else if (score >= 80)

        return 'B';

    else if (score >= 70)

        return 'C';

    else if (score >= 60)

        return 'D';

    return 'B';

}

void displayResults(int *scores, char grade)

{

    for (int i = 0; i < 4; i++)

        cout << "Test " << i + 1 << ": " << scores[i] << endl;

    cout << "Grade: " << grade << endl;

}

int main()

{

    int scores[4];

    cout << "Welcome to the compute letter grade program\n";

    inputData(scores);

    char grade = calcGrade(scores);

    displayResults(scores, grade);

}

Output:


Related Solutions

C++ Program: Write another program (in C++) that will allocate a local static array of integers...
C++ Program: Write another program (in C++) that will allocate a local static array of integers and then a dynamic array of integers. Are they stored next to each other? You can examine this by examining the memory addresses where they are located. As described in class, on some systems the size of a dynamic array is actually stored in the bytes previous to a dynamically allocated array. Through some experiments on your own, try to see if this is...
Write C program that reorders elements of an array of integers such that the new order...
Write C program that reorders elements of an array of integers such that the new order is in descending order (first number being the largest). Must have a main function and a swap function. - int main() will declare an array with the values { 32, 110, 79, 18, 22, 2}. This array will be passed to the swap function. - the void swap function will perform the necessary operations to reorder the elements of the array. - After swap()...
Write a C++ program to find the number of pairs of integers in a given array...
Write a C++ program to find the number of pairs of integers in a given array of integers whose sum is equal to a specified number.
1. a. In C++, Write a program that creates an array of 20 integers and initializes...
1. a. In C++, Write a program that creates an array of 20 integers and initializes it with the even values starting from 200. i.e. 200, 202, 204…. b. Write the elements of the array to the file even.txt, each element on a separate line. Try to use a single for loop for initializing the array and writing to file. You will need a separate counter for initializing the array. 2. a. Write another program that opens the file even.txt...
Write a C++ program to find K largest elements in a given array of integers. For...
Write a C++ program to find K largest elements in a given array of integers. For eeample, if K is 3, then your program should ouput the largest 3 numbers in teh array. Your program is not supposed to use any additional array.
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers as follows: Assign {35,20,-43,-10,6,7,13} -Create a one dimensional array of 7 Boolean values as follows: Assign {true,false,false,true,false,true,false} -Create a one dimensional array of 7 floating-point values as follows: Assign {12.0f,1.5f,-3.5f,-2.54f,3.4f,45.34f,22.13f} -Declare sum as integer and set it to 0. -Declare sumf as float and set it to 0.0f. -Use a for loop to go through each element of the Boolean array, and if an...
In C create an array of 4 integers. Assign a pointer to the array. Use the...
In C create an array of 4 integers. Assign a pointer to the array. Use the pointer to find the average value of the elements in the array and display the results on the screen.
use c++ 1 a)Write a console program that creates an array of size 100 integers. Then...
use c++ 1 a)Write a console program that creates an array of size 100 integers. Then use Fibonacci function Fib(n) to fill up the array with Fib(n) for n = 3 to n = 103: So this means the array looks like: { Fib(3), Fib(4), Fib(5), ...., Fib[102) }. For this part of the assignment, you should first write a recursive Fib(n) function. .For testing, print out the 100 integers. b) For the second part of this assignment, you must...
c++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt...
c++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt the user for 6 integer values and store them in arr. Prompt the user for a target integer target. Search for targetin arr. If targetis found to match an element in the arr, then the program prints out a message which contains the address of the found element, otherwise, if no element found then the message “the element target not found” will be printed...
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT