Question

In: Computer Science

OBJECTIVE-C For this program a teacher needs to be able to calculate an average of test...

OBJECTIVE-C

For this program a teacher needs to be able to calculate an average of test scores for students in their course. Your program must ask the Professor ho many students and how many tests will be averaged per student. Your program should then allow the Professor to enter scores for each student one at a time and then average those scores together. For example, if a student has 5 scores to be entered and the scores are 80, 60, 65,98, and 78 the average should be 76.2%

Here is what I got.

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

int students, numOfScores, scores, sum;
float average;
NSLog(@"Enter number of students");
scanf("%i", &students);
NSLog(@"Enterh number of scores");
scanf("%i", &numOfScores);
int n;
int s;
for (n = 1; n <= students; n++){
for (s = 1; s <= numOfScores; s++)
{

NSLog(@"Enter the score");
scanf("%i", &scores);
sum = sum + scores;   
}
  
}
average = (float) sum / numOfScores;
NSLog(@"An average score is %f", &average);

return 0;
}

Solutions

Expert Solution

Please find your solution below and if any doubt or need change comment and do upvote.

CODE:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
   int students, numOfScores, scores, sum;
   float average;
   //take user input
   NSLog(@"Enter number of students");
   scanf("%d", &students);
   NSLog(@"Enterh number of scores");
   scanf("%d", &numOfScores);
   int n;
   int s;
   
   //using loop sum the enter values
   for (n = 1; n <= students; n++)
   {
       sum=0;//reset to 0 for each next student
       for (s = 1; s <= numOfScores; s++)
       {
         
         //add thte scores
          NSLog(@"Enter the score");
          scanf("%d", &scores);
          sum = sum + scores;   
       }
       //find the average and print it
       average=(float)sum/numOfScores;
       NSLog(@"An average score is %.1f", average);
   }


return 0;
}

OUTPUT:


Related Solutions

MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines: - Your program should ask the user for the number of students that are in the class. This number should help you declare your array. - Use the function seen in class to scan the grades of the array. In other words, we will populate the array...
Joe’s Pizza Palace needs a C++ program to calculate the number of slices a pizza of...
Joe’s Pizza Palace needs a C++ program to calculate the number of slices a pizza of any size can be divided into. The program should perform the following steps: A. Ask the user for the diameter of the pizza in inches. B. Divide the diameter by 2 to get the radius. C. Calculate the number of slices that may be taken from a pizza of that size if each slice has an area of 14.125 square inches. D. Display a...
IN C++ Write a program that uses nested loops to collect data and calculate the average...
IN C++ Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the ­­program should display the...
......C++ PROGRAM.... Teacher would like us to split this program into a header file(filename.h), and a...
......C++ PROGRAM.... Teacher would like us to split this program into a header file(filename.h), and a .cpp file(filename.cpp). He gave us all the code, we just need to split it up. I do not quite understand how to do it. Please send output screenshot to show validation. #include <iostream> using namespace std; //public class class Account{ public: //instance variables double amount;    //creates account and sets amount with users account set-up value Account(double a){ amount = a; }    //adds...
A local instructor wants you to write a c++ program using arrays to calculate the average...
A local instructor wants you to write a c++ program using arrays to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60 or above...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number...
Instructions: Write a program to calculate students’ average test scores and their grades. You may assume...
Instructions: Write a program to calculate students’ average test scores and their grades. You may assume the following input data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63...
Directions: Write a program to calculate students’ average test scores and their grades. You may assume...
Directions: Write a program to calculate students’ average test scores and their grades. You may assume the following input data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63...
Write a program in C A teacher will assign homework and give the number of days...
Write a program in C A teacher will assign homework and give the number of days for the students to work on. The student is responsible for calculating the due date. The teacher does not collect homework on Friday or weekend. Write a C program that let the user enter today’s day of the week (0 for Sunday, 1 for Monday, etc.) and the number of days to allow the students to do the work, which may be several weeks....
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT