in C++ You are to define a structure containing the id number, three test scores, and their average, for each student in a class of 20. The file pr2data.txt is included and contains the data. The program is to include the following:
pr2data.txt
1234 52 70 75
2134 90 75 90
3124 90 95 98
4532 11 17 81
5678 20 12 45
6134 34 45 55
7874 60 100 56
8026 70 10 66
9893 34 9 77
2233 78 20 78
1947 45 40 88
3456 78 55 78
2877 55 50 99
3189 87 94 74
2132 75 100 80
4602 89 50 91
3445 78 60 78
5405 11 11 0
4556 78 20 10
6999 88 98 89
Please let me know if anything is required.
Copyable code:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
//the structure to store the file contents
struct Student_Records {
int id;
int score1;
int score2;
int score3;
};
//function ti calculate hte student Average
float findstavg(int q1,int q2,int q3)
{
return (q1+q2+q3)/3.0;
}
//function to find the high score
int findhigh(int q[],int n)
{
int max =q[0];
for(int i=1;i<n;i++)
{
if(q[i]>max) //condition for max
{
max=q[i];
}
}
return max;
}
//function to find the low score
int findlow(int q[],int n)
{
int min =q[0];
for(int i=1;i<n;i++)
{
if(q[i]<min)//condition for min
{
min=q[i];
}
}
return min;
}
//function to find the quiz average
float findqzavg(int q[],int n)
{
int s=0;
for(int i=0;i<n;i++)
{
s+=q[i]; //calculating the sum
}
double avg = s/(n*3.0); //calculating the avg
return avg;
}
int main()
{
string line;
ifstream myfile("pr2data.txt"); //opening the input file
ifstream myfile1("pr2data.txt");
//program to find the number of lines are present in the file for
declaring the array sozes
int linecount=0;
//condition to check whether able to open the file or not
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
linecount++;
}
myfile.close();
}
else {cout << "Error, the file does not exist\n"; }
struct Student_Records student_array[linecount];
//code to perform the required actions
if (myfile1.is_open())
{
ofstream outfile;
outfile.open("output.txt"); //output file to write the
contents
outfile<<"Student Quiz1 Quiz2 Quiz3 Average\n";
//arrays to store the values
int student[linecount];
int quiz1[linecount];
int quiz2[linecount];
int quiz3[linecount];
int j=0;
while ( getline (myfile1,line) )
{
outfile<<line;//writintg the contents to the output
file
int s[4];
string delimiter = " "; //splitting the line with spaces
int i=0;
size_t pos = 0;
string token;
while ((pos = line.find(delimiter)) != string::npos)
{
token = line.substr(0, pos);
stringstream geek(token); //converting the string to int
int x = 0;
geek >> x;
s[i]=x;
i++;
line.erase(0, pos + delimiter.length());
}
//converting the string to int
token = line;
stringstream geek(token);
int x = 0;
geek >> x;
s[i]=x;
//assigning the values into the structure
student_array[j].id=s[0];
student_array[j].score1=s[1];
student_array[j].score2=s[2];
student_array[j].score3=s[3];
student[j]=student_array[j].id;
quiz1[j]=student_array[j].score1;
quiz2[j]=student_array[j].score2;
quiz3[j]=student_array[j].score3;
//calling the student average function
float std_avg = findstavg(quiz1[j],quiz2[j],quiz3[j]);
outfile<<" "<<std_avg<<"\n"; //writintg the
student average details to the output file
j++;
}
int high_score_q1 = findhigh(quiz1,22);//function to find the high
score values
int high_score_q2 = findhigh(quiz2,22);//function to find the high
score values
int high_score_q3 = findhigh(quiz3,22);//function to find the high
score values
//writintg the high score values of each quiz to the output
file
outfile<<"High score "<<high_score_q1<<"
"<<high_score_q2<<" "<<high_score_q3<<"
\n";
int low_score_q1 = findlow(quiz1,22); //function to find the low
score values
int low_score_q2 = findlow(quiz2,22); //function to find the low
score values //function to find the low score values
int low_score_q3 = findlow(quiz3,22);
//writintg the low score values of each quiz to the output
file
outfile<<"Low score "<<low_score_q1<<"
"<<low_score_q2<<" "<<low_score_q3<<"
\n";
float avg_score_q1 = findqzavg(quiz1,22);//function to find the
quiz average values
float avg_score_q2 = findqzavg(quiz2,22);//function to find the
quiz average values
float avg_score_q3 = findqzavg(quiz3,22);//function to find the
quiz average values
//writintg the average quiz values of each quiz to the output
file
outfile<<"Quiz Average "<<avg_score_q1<<"
"<<avg_score_q2<<" "<<avg_score_q3<<"
\n";
myfile.close();
}
return 0;
}
Inputfile screenshot :
output screenshot :
Testcase1 :
Testcase 2:
I gave the file name as pr2dat.txt instead of pr2data.txt so we should get an error as the input file is not exist, attaching the screenshot for the same.
in C++ You are to define a structure containing the id number, three test scores, and...
C++ program that reads students' names followed by their test scores (5 scores) from the given input file, students.txt. The program should output to a file, output.txt, each student's first name, last name, followed by the test scores and the relevant grade. All data should be separated by a single space. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, an array of testScores of type int...
C++ Sorting and Searching 1. Mark the following statements as true or false. a. A sequential search of a list assumes that the list elements are sorted in ascending order. b. A binary search of a list assumes that the list is sorted. 2. Consider the following list: 63 45 32 98 46 57 28 100 Using a sequential search, how many comparisons are required to determine whether the following items are in the list or not? (Recall that comparisons...
Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...
Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...
This lab is to give you more experience with C++ Searching and Sorting Arrays Given a file with data for names and marks you will read them into two arrays You will then display the data, do a linear search and report if found, sort the data, do a binary search. Be sure to test for found and not found in your main program. Read Data Write a function that reads in data from a file using the prototype below....
1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand. b. Explain why you chose this technique over others. Year 3 Year 1 Year 2 Actual Actual Actual Forecast Forecast Forecast Demand Demand Demand Week 1 52 57 63 55 66 77 Week 2 49 58 68 69 75 65 Week 3 47 50 58 65 80 74 Week 4 60 53 58 55 78 67 57 Week 5 49 57 64 76 77...
C++: Create a grade book program that includes a class of up to 20 students each with 5 test grades (4 tests plus a Final). The sample gradebook input file (CSCI1306.txt) is attached. The students’ grades should be kept in an array. Once all students and their test scores are read in, calculate each student’s average (4 tests plus Final counts double) and letter grade for the class. The output of this program is a tabular grade report that is...
Write a main function that declares the names, marks, number of elements as well as the value to be searched for and the index of the returned function calls. Read and display the contents of names and marks. Ask the user for a name and using the linear search return the index to the user. If -1 is returned then the name is not in the file. Otherwise write out the name and mark for that student. Sort the arrays...
Your IT department provided you data on patients that received ER services, their GHHS, and their recovery time. Prepare a report to share with the owners of the facility that will help you make informed decisions about how long you can expect a patients’ recovery time would be based on their GHHS. Based on your findings provide recommendations on your plan moving forward to improve the functioning of your facilities in generating revenue. Prepare a report that addresses each of...
Must be in Python 3 exercise_2.py # Define the Student class class Student(): # Initialize the object properties def __init__(self, id, name, mark): # TODO # Print the object as an string def __str__(self): return ' - {}, {}, {}'.format(self.id, self.name, self.mark) # Check if the mark of the input student is greater than the student object # The output is either True or False def is_greater_than(self, another_student): # TODO # Sort the student_list # The output is the sorted...