Question

In: Computer Science

IN C++ As in previous labs, RESIST THE URGE TO CODE! Determine what data will be...

IN C++

As in previous labs, RESIST THE URGE TO CODE! Determine what data will be necessary in order to complete this task. Then design the steps necessary to process that data. Do you need if statements? Do you need loops? Do you need if statements within your loops?

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 for loop.  

Test Data:

            Ben Simmons             70

            Carson Wentz             80

            Joel Embiid                 90

            Bryce Harper             75

Solutions

Expert Solution

Yes we need if contdition to find the maximum marks scored by the student

Yes we need for loop to read the n students names and their marks

yes we need a if condtion inside the loop

when the student marks are entered we compare them with max marks

so we need if inside the loop

Code:

#include <iostream>
using namespace std;
int main()
{
int n,max=0,i;
float sum=0;/*Declaring variables*/
cout<<"Enter no of students:";
cin>>n;/*Reading no of students*/
int marks[n];
string name[n];/*Declaring 2 array one for marks other for names*/
for(i=0;i<n;i++)
{/*This loop iterates 0 to n-1*/
cout<<"Enter the name of student:";
cin.get();
getline(cin,name[i]);/*Reading students name*/
cout<<"Enter student marks:";
cin>>marks[i];/*Reading students marks*/
sum+=marks[i];/*Total of the all students*/
if(marks[i]>marks[max])
{
/*If student marks is greater than the marks[max ]
then we assign the max= current student index*/
max=i;
}
}
cout<<"Heighest Score: "<<marks[max]<<"\nStudent Name:"<<name[max]<<endl;
/*Printing the highest score and student name*/
cout<<"Average Score:"<<sum/n<<endl;/*Average*/
cout<<"Difference between Heighest and Average: "<<marks[max]-sum/n<<endl;/*Difference between Heighest and Average*/

return 0;
}

Output:

Indentation:


Related Solutions

Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
Windows Interprocess communication. WM_CopyData IPC (data copy) - source code (c++) windows data copy IPC code
Windows Interprocess communication. WM_CopyData IPC (data copy) - source code (c++) windows data copy IPC code
What decisions on the basis of this information, including the same data for the previous period...
What decisions on the basis of this information, including the same data for the previous period and possibly two years prior, can investors or shareholders take (focus on future growth, evolution of risk level, or volatility of future earnings and evolution of the 'time horizon of visibility' into the firm's future)?
package labs; Complete the following code /* * Purpose: Look at LinkedList, overloaded methods and *...
package labs; Complete the following code /* * Purpose: Look at LinkedList, overloaded methods and * write a simple method to check if the LinkedList actually contains any loops/cycles in it. */ public class LinkedList<E> { private static class Node<E> { E data; Node<E> next; public Node(E d) { data=d; next=null; } } private Node<E> head; private Node<E> tail; /* * data of type E, first gets put into a Node * and then the Node gets added onto the...
Create C# code that can search a text file and output the data at the line...
Create C# code that can search a text file and output the data at the line number inputted and amount of entries needed. Example of call in command window: Search16s filename.txt 273   10 Where 273 is the line number to start the output from, and 10 is the number of sequences that the program should output. The number of sequences entered on call should always be a odd number or give an error in console. The output should also display...
Problem 1. Determine the length, the size, and the minimal distance for each q-ary code C...
Problem 1. Determine the length, the size, and the minimal distance for each q-ary code C below. How many errors can each code correct? detect? (a) C = { (0, 0, 0, 0, 0, 0), (0, 1, 1, 1, 1, 0), (1, 0, 0, 0, 0, 1), (1, 1, 1, 1, 1, 1) }. Here q = 2. (b) C = { (0, 0, 0, 0, 0, 0, 0), (2, 1, 0, 2, 1, 0, 1), (2, 2, 2, 2,...
Determine the output using C++ of the following code fragment i) double *pt; double a[3] =...
Determine the output using C++ of the following code fragment i) double *pt; double a[3] = {1.2, 2.3, 3.4}; pt = &a[1]; pt += 1; cout << *pt << endl; ii) int i = 1; while (i <= 4) { int num = 1; for (int j = 1; j <= i; j++) { cout << num << "bb"; num *= 3; } cout << endl; i++; }
I would like the following code in PYTHON please, there was a previous submission of this...
I would like the following code in PYTHON please, there was a previous submission of this question but I am trying to have the file save as a text file and not a json. Any help would be greatly appreciated. Create an application that does the following: The user will enter product codes and product numbers from the keyboard as strings. The product code must consist of four capital letters. The product number can only consist of numeric characters, but...
what will be the code in C programming for the client and server chat application for...
what will be the code in C programming for the client and server chat application for the below issue :- write the C Programming code that able client have a unique ID to be known by the server
3. Given the initial rate data for the reaction A + B –––> C, determine the...
3. Given the initial rate data for the reaction A + B –––> C, determine the rate expression for the reaction. [A], M [B], M Δ [C]/ Δ t (initial) M/s 0.215 0.150 5.81 x 10–4 0.215 0.300 1.16 x 10–3 0.430 0.150 2.32 x 10–3 A) (Δ[C]/Δt) = 1.80 x 10–2 M –1 s –1 [A][B] B) (Δ[C]/Δt) = 3.60 x 10–2 M –1 s –1 [A][B] C) (Δ[C]/Δt) = 1.20 x 10–1 M –2 s –1 [A][B]2 D)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT