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

As in previous labs, please write the Java code for each of the following exercises in...
As in previous labs, please write the Java code for each of the following exercises in BlueJ. For each exercise, write a comment before the code stating the exercise number. Make sure you are using the appropriate indentation and styling conventions Exercise 1 (15 Points) In BlueJ, create a new project called Lab6 In the project create a class called Company Add instance data (fields) for the company name (a String) and the sales for the current period (a double)...
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...
This is in Python: Alter your code for previous Do It Now problem, with the change...
This is in Python: Alter your code for previous Do It Now problem, with the change that the row should only be printed by the second number that the user enters. For example, the user enters two numbers of 5 and 7 for the two input lines in the code, and the following will be printed: 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT