Question

In: Computer Science

2. Write a c++ program that takes from the user the ​number of courses​ and constructs...

2. Write a c++ program that takes from the user the ​number of courses​ and constructs 3 ​dynamic 1D arrays​ with size courses+1. Each array represents a student. Each cell in the array represents a student’s mark in a course. In the last cell of each 1D array you should calculate the average mark of that student. Then output the average mark of all students in each course. Delete any allocated memory. Example Number of courses : 4 50 60 70 20 100 90 80 70 80 90 100 30 Output: 50 60 70 20​ 50 100 90 80 70 ​85 80 90 100 30 ​75 Avg of course 1 = 76.66 Avg of course 2 = 80 Avg of course 3 = 83.33 Avg of course 4 = 40.

Solutions

Expert Solution

#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
//variable declaration
int courses;
  
//display message
cout<<"Enter the number of courses: ";
cin>>courses;
float avgStu[3], avgCourse[courses];
  
//dynamic array declaration
int *std1 = new int[courses+1];
int *std2 = new int[courses+1];
int *std3 = new int[courses+1];
  
  
//display message
cout<<"Enter the marks of student: "<<endl;
avgStu[0] = 0;
avgStu[1] = 0;
avgStu[2] = 0;
  
//input the markes in each of the courses and calculate the average
for(int j=0; j<courses; j++)
{
cin>>std1[j];
avgStu[0] = avgStu[0] + std1[j];
avgCourse[j] = avgCourse[j] + std1[j];
  
}
  
//input the markes in each of the courses and calculate the average
for(int j=0; j<courses; j++)
{
cin>>std2[j];
avgStu[1] = avgStu[1] + std2[j];
avgCourse[j] = avgCourse[j] + std2[j];
}
  
//input the markes in each of the courses and calculate the average
for(int j=0; j<courses; j++)
{
cin>>std3[j];
avgStu[2] = avgStu[2] + std3[j];
avgCourse[j] = avgCourse[j] + std3[j];
}
  
//set the student average at the last column
std1[courses] = avgStu[0] / (float) courses;
std2[courses] = avgStu[1] / (float) courses;
std3[courses] = avgStu[2] / (float) courses;
  
//display the result
cout<<endl<<"Student 1 ";
for(int j=0; j<=courses; j++)
{
cout<<setw(5)<<std1[j]<<" ";
}
cout<<endl<<"Student 2 ";
for(int j=0; j<=courses; j++)
{
cout<<setw(5)<<std2[j]<<" ";
}
cout<<endl<<"Student 3 ";
for(int j=0; j<=courses; j++)
{
cout<<setw(5)<<std3[j]<<" ";
}
cout<<endl<<"Average: ";
for(int i=0; i<courses; i++)
cout<<setw(5)<<setprecision(2)<<avgCourse[i]/3.0<<" ";

return 0;
}

OUTPUT:



Related Solutions

how to write a cpp program that takes a number from a user, and print the...
how to write a cpp program that takes a number from a user, and print the sum of all numbers from one to that number on screen? using loop interation as basic as possible.
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
write a java program that takes three numbers from the user and print the greatest number...
write a java program that takes three numbers from the user and print the greatest number (using if-statement). sample output: input the first number:35 input the second number:28 input the third number:87 the greatest number:87
Write a C++ console program that prompts a user to enter information for the college courses...
Write a C++ console program that prompts a user to enter information for the college courses you have completed, planned, or are in progress, and outputs it to a nicely-formatted table. Name the CPP as you wish (only use characters, underscores and number in your file name. DO NOT use blank). Its output should look something like this: Course Year Units Grade ---------- ---- ----- ----- comsc-110 2015 4 A comsc-165 2016 4 ? comsc-200 2016 4 ? comsc-155h 2014...
Write a C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
C programming Get a number from the user and write a program that checks to see...
C programming Get a number from the user and write a program that checks to see if the inputted number is equal to x*x+x and x must be greater than 0. For example, if the user inputs 12. The program should check to see if 12 = x*x+x. In this case it is true because 3*3+3 = 12.
Write a program in C that prompts the user for a number of seconds and then...
Write a program in C that prompts the user for a number of seconds and then converts it to h:m:s format. Example: 5000 seconds should display as 1:23:20 (1 hour, 23 minutes, 20 seconds.) Test with several values between about 100 seconds and 10,000 seconds. use unint and remainders for this and keep it as simple as possible.
C++ [2] Write a program that prompts the user to enter a non-negative decimal number and...
C++ [2] Write a program that prompts the user to enter a non-negative decimal number and a base in the range 2 <= base <= 16. Write a function multibaseOutput() that displays the number in the specified base. The program terminates when the user enters a number of 0 and a base 0. Run: Enter a non-negative decimal number and base (2 <= B <= 16) or 0 0 to terminate: 155 16     155 base 16 is 9B Enter...
Write a program that prompts the user for an even number from 2 to 100 until...
Write a program that prompts the user for an even number from 2 to 100 until the number 90 is encountered. Not including the 90, calculate the minimum value. In case you know what this means: DO NOT USE LISTS! We will look into the use of lists later. This has to be done in the python program. Here's what I have so far: inp = 0 min = 0 while inp != 90:     inp = int(input("Please enter an even...
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT