Concept explainers
Hi, i have a problem with this code, which is it only takes the last scores entered by the user when i want to take all the scores of each student and do the avrage calculation and display them like the output ill post with the question.
The code:
#include <iostream>
#include <string>
using namespace std;
void readStudentInfo (string [],int,double[]);
void calcAvg (double[],int);
char getGrade (char[],int, double);
void printResults(string[],double[],double[],int);
void line()
{
cout << "--------------------------------";
}
const int N=2; // Number of students
const int S=5; // Number of tests
int main()
{
string StName[N];
double StScore[S];
printResults(StName,StScore,StScore,N);
}
void readStudentInfo(string names[],int students,double Average[],double Score[])
{
for (int i=0; i<students;i++)
{
cout << "Please enter student name (" << i+1 << "): ";
getline(cin, names[i]);
cout << "\n";
}
for (int j=0; j<students;j++)
{
cout << "Enter all " << S << " scores for " << names[j] << " : " << "\n";
for (int x=0; x<S; x++)
{
cin >> Score[x];
Average[x]+=Score[x];
}
}
}
void calcAvg (string names[], double Average[],int students,double Score[])
{
double StSum=0;
for (int i=0; i<students;i++)
{
StSum=0;
for (int j=0; j<S*N; j++)
{
StSum+=Score[j];
}
cout <<" StSum: " << StSum << endl;
Average[i] = StSum/S;
cout << "AVERAGE IS: " << Average[i] << endl;
}
}
void printResults(string names[],double Score[],double Average[],int students)
{
readStudentInfo(names,students,Average, Score);
double classAvg=0,scoreSum=0;
char grade[N],tempGrade[1],ClassGrade;
double tempAvg=0;
calcAvg(names,Score,students, Score);
for (int x=0;x<students;x++)
{
tempAvg = Average[x];
grade[x] = getGrade(grade,students,tempAvg);
classAvg+= Average[x];
}
classAvg= classAvg/N;
ClassGrade = getGrade(tempGrade,students,classAvg);
cout << "\n";
line ();
cout << "\n";
cout << "Class Average: " << classAvg << endl;
cout << "Class Grade : " << ClassGrade << endl;
line ();
cout << "\n";
for (int i=0; i<students; i++)
{
cout << " Name: " << names[i] << endl;
cout << " Average: " << Average[i] << endl;
cout << " Grade: " << grade[i] << endl;
line ();
cout << "\n";
}
}
char getGrade (char grade[],int students, double Avg)
{
if (Avg>=90)
return 'A';
if (Avg>=80)
return 'B';
if (Avg>=70)
return 'C';
if (Avg>=60)
return 'D';
if (Avg<60)
return 'F';
}
Step by stepSolved in 3 steps with 2 images
- in the C++ version please suppose to have a score corresponding with probabilities at the end and do not use the count[] function. Please explain the detail when coding. DO NOT USE ARRAY. The game of Pig The game of Pig is a dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 ("pig") is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions: roll - if the player rolls 1: the player scores nothing and it becomes the opponents turn. 2 - 6: the number is added to the player's turn total and the player's turn continues. hold - The turn total is added to the player's score and it becomes the opponent's turn. This game is a game of probability. Players can use their knowledge of probabilities to make an educated game decision. Assignment specifications Hold-at-20 means that the player will choose to roll…arrow_forwardC++ Code: Write a program that finds word differences between two sentences. The input begins with an integer indicating the number of words in each sentence. The next input line is the first sentence and the following input line is the second sentence. Assume that the two sentences have the same number of words and no more than 20 words each. The program displays word pairs that differ between the two sentences. One pair is displayed per line. Ex: If the input is: 6 Smaller cars get better gas mileage Tiny cars get great fuel economy then the output is: Smaller Tiny better great gas fuel mileage economy Add a function named ReadSentences to read the input sentences into two string vectors. void ReadSentences(vector<string>& sentence1Words, vector<string>& sentence2Words, int wordCount) main() already contains code to read the word count and call ReadSentences(). Complete main() to display differing word pairs.arrow_forward5. use c code to Write a stringSearch function that gets two strings one called needle and the other called haystack. It then searches in the Haystack for the needle. If it finds it, it returns the index of where the needle starts in the haystack. If the needle cannot be found, it should return -1 Prototype: int stringSearch(char needle[], char haystack) Example1: Haystack: “This is just an example” Needle: “just” Result: 8 Example2: Haystack: “This is just an example” Needle: “This” Result: 0 Example3: Haystack: “This is just an example” Needle: “this” Result: -1 Hint: all the answer need to include an output and use c code to answerarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education