Question

Create a C++ program to : Prompt user for seven test score Store the scores into...

Create a C++ program to :

  1. Prompt user for seven test score
  2. Store the scores into an array
  3. Print the array before and after sorting
  4. Print the test average
  5. Convert the average to letter grade
  6. Search for a test score 90, using linear search
    1. Print, if test score 90 was found and at what position
  7. Add Comments

SEPARATE THE FILES INTO 3 : header.h, functions.cpp, main.cpp

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code for the above program is given below, I have commented in line for the explanation.

There are 3 separate files:-

functions.cpp

void sort(int arr[],int n) // function to sort
{
for(int i=0;i<n-1;i++) // Bubble sort
{
for(int j=i+1;j<n;j++)
{
if(arr[j]<arr[i])
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}


float average(int arr[],int n) // function for average
{
float sum=0;
for(int i=0;i<n;i++)
{
sum+=arr[i];
}
  
return sum/n;
}

int search(int arr[],int n,int k) // linear search for number k
{
int temp=-1;
for(int i=0;i<n;i++)
{
if(arr[i]==k)
{
temp=i+1;
}
}
return temp;
}

header.h

// In this file we define definition fo each function
void sort(int arr[],int n);
float average(int arr[],int n);
int search(int arr[],int n,int k);

main.cpp

#include <iostream>
#include "header.h" // icluding header.h file
using namespace std;

int main()
{
int n=7;
cout<<"Enter seven Test scores: ";
int arr[n]; // defining array
  
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
  
cout<<"Before sorting: \n";
for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
  
sort(arr,n); // Sorting the array
cout<<"\nAfter sorting: \n";
  
for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
  
float avg = average(arr,n); // calling average function
  
cout<<"\nAverage is: "<<avg<<"\n";
if(avg<=50) cout<<"Grade is C";
else if(avg<=80) cout<<"Grade is B";
else cout<<"Grade is A";
  
int srch = search(arr,n,90); // calling search function
  
if(srch!=-1)
{
cout<<"\nScore 90 was found at: "<<srch<<endl;
}
  

return 0;
}

Output

Hope it clears your doubt :)

Add a comment
Know the answer?
Add Answer to:
Create a C++ program to : Prompt user for seven test score Store the scores into...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a C++ program to : Prompt user for seven test score Store the scores into...

    Create a C++ program to : Prompt user for seven test score Store the scores into an array Print the array before and after sorting Print the test average Convert the average to letter grade Search for a test score 90, using linear search Print, if test score 90 was found and at what position Add Comments SEPARATE THE FILES INTO 3 : header.h, functions.cpp, main.cpp

  • In Java Main method Your main program will prompt the user for a test name and...

    In Java Main method Your main program will prompt the user for a test name and the number of scores the user will enter. After creating an arraylist to hold the scores, prompt the user for all the scores to hold in the arraylist. After all the scores are entered, then repeat back the score & letter grade. GradeBook Object Create an instance of a GradeBook object and pass the test name and arraylist to set the instance variables. At...

  • in C++ Create a program that will calculate a student’s grade average of 5 test scores...

    in C++ Create a program that will calculate a student’s grade average of 5 test scores and assign a letter grade for a student. The program should use a class to store the student’s data including the student’s name and score on each of 5 tests. The program should include member functions to 1) get the student’s test scores, 2) calculate the average of the test scores, and 3) display the results as follows: Test scores for Mary: 100 90...

  • Write a program that asks the user to enter five test scores. The program should display...

    Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program: calcAverage—This function should accept five test scores as arguments and return the average of the scores. determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale: Round the average...

  • Write a c++ program which uses a structure having the indicated member names to store the...

    Write a c++ program which uses a structure having the indicated member names to store the following data: Name (student name) IDnum (student ID number) Tests (an array of three test scores) Average (average test score) Grade (course grade) The program will keep a list of three test scores for one student. The program may prompt the user for the name, ID number, and test scores, or these may be assigned within the program. The average test score will be...

  • Write a program that asks the user to enter five test scores. The program should display...

    Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program: calcAverage—This function should accept five test scores as arguments and return the average of the scores. determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale: Score Letter Grade...

  • Write a javascript program that asks the user to enter five test scores. The program should...

    Write a javascript program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: calcAverage—This method should accept five test scores as arguments and return the average of the scores. determineGrade—This method should accept a test score as an argument and return a letter grade for the score,

  • Write a C++ program that lets a maker of chips and salsa keep track of their...

    Write a C++ program that lets a maker of chips and salsa keep track of their sales for five different types of salsa they produce: mild, medium, sweet, hot, and zesty. It should use two parallel five-element arrays: an array of strings that holds the five salsa names and an array of integers that holds the number of jars sold during the past month for each salsa type. The salsa names should be stored using an initialization list at the...

  • 1. Create a program that takes a numerical score and outputs a letter grade. 2. In...

    1. Create a program that takes a numerical score and outputs a letter grade. 2. In this program, create two void functions titled makeScore and theGrade with an int argument. 3. The function makeScore should have a Reference parameter and theGrade should have a Value parameter. Note: Specific numerical scores and letter grades are listed below: 90-100 = Grade A 80-89 = Grade B 70-79 = Grade C 60-69 = Grade D 0-59 = Grade F 4. The function makeScore...

  • PHYTHON NOT JAVA!!! need HELP ASAP!!! This program gets a series of test scores and #...

    PHYTHON NOT JAVA!!! need HELP ASAP!!! This program gets a series of test scores and # calculates the average of the scores with the # lowest score dropped. def main(): # Get the test scores from the user and store it in a variable called scores.    # Get the total of the test scores and store it in a variable called total.    # DONE - Get the lowest test score and store it in a variable called lowest....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT