Question

In: Computer Science

The Programming Language is C++ Objective: The purpose of this project is to expose you to:...

The Programming Language is C++

Objective:

The purpose of this project is to expose you to:

One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions.

Problem Specification:

Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three quizzes for each student during the term. Each student is identified by a four-digit student ID number. The number of students in the class is unknown, therefore we need to detect end of file to stop. The file pr2data.txt is included and contains the data.

The program calculates the statistics for each student and for each quiz as shown in the sample output. The output goes to a file and is in the same order as the input and should be similar to the following: any other improvements to the output are welcomed.

                  CIS Department – Fall 2018

                     CIS 161 Class Statistics

Student                        Quiz 1               Quiz 2              Quiz 3          Average      

1234                          78                 83              87                   82.67            

2134                          67                77              84                  76.00

3124                          77                89              93                  86.33

High score                 78                89              93

Low score                 67                77              84

Quiz Average            73.4              83.0           88.2

pr2data

1234   52   70   75
2134   90   76   90
3124   90   95   98
4532   21   17   81
5678   20   22   45
6134   34   45   55
7874   60   99   56
8026   70   10   66
9893   34   09   77
2233   78   20   78
1947   45   40   88
3456   78   55   78
2877   55   50   95
3189   70   98   78
2132   77   97   80
4602   89   50   91
3445   78   60   78
5405   35   33   15
4556   78   20   18
6999   88   98   89
9898   48   78   68
2323   78   20   78

Requirements:

  • Main () is used as a driver function; the only statements in main are function calls.
  • Your program needs to follow my hierarchical chart.
  • Define a new type for each array of a type.
  • Declare an array for each of the data items.
  • Setdata() reads the data from the file into arrays.
  • Getdata prints the results into a file.
  • Findstavg calculates each student’s average and stores it into an array.
  • Findqzavg finds the average of a quiz and returns the average as its value
  • Findhigh finds the largest quiz in an array and returns it as its value.
  • Findlow finds the smallest quiz in an array and returns it as its value.

Grading Criteria:

5 points      There are sufficient comments in the programs.

5 points      use the typedef to define all arrays.

5 points      a flowchart of the function main () is included and is correct (only main()).

5 points      use a counter to count the number of elements read.

5 points      generate an error if file does not exist, or if not open.

10 points      loop is included and reads the data until it encounters the end of file.

5 points      proper passing by value/by reference for all functions.

5 points      the function findstavg () finds the float average for each student.

5 points      the function findhigh () is clear correct and returns the highest quiz.

5 points      the function findlow () is clear correct and returns the lowest quiz.

10 points      the function findqzavg () is clear correct and returns a quiz average.

5 points      every function has specifications.

5 points      headings, column titles are printed, formatted and looks nice.

5 points      data/calculated results are printed with proper spacing and proper formatting.

15 points      the program runs correctly and produces the intended results.

5 points       output are printed to a file.

Solutions

Expert Solution

Solution:

Givendata:

Objective:

The purpose of this project is to expose you to:

One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions.

Problem Specification:

Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three quizzes for each student during the term. Each student is identified by a four-digit student ID number.

Answer:

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;

//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"; }
  
//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[22];
int quiz1[22];
int quiz2[22];
int quiz3[22];
  
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 to arrays
student[j]=s[0];
quiz1[j]=s[1];
quiz2[j]=s[2];
quiz3[j]=s[3];
  
//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.

please giveme thumbup....................


Related Solutions

Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output. Assignment: It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory. You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students to generate a linked list of playing card based on data read from a file and to write out the end result to a file. linkedList.h Create a header file name linkedList Include the following C header files: stdio.h stdlib.h string.h Create the following macros: TRUE 1 FACES 13 SUITS 4 Add the following function prototypes: addCard displayCards readDataFile writeDataFile Add a typedef struct...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
Objective: The purpose of this programming assignment is to practice using STL containers. This problem is...
Objective: The purpose of this programming assignment is to practice using STL containers. This problem is selected from the online contest problem archive (Links to an external site.), which is used mostly by college students world wide to challenge their programming ability and to prepare themselves for attending programming contests such as the prestige ACM International Collegiate Programming Contest (Links to an external site.). For your convenience, I copied the description of the problem below with my note on the...
In this programming assignment, you will write C code that performs recursion. For the purpose of...
In this programming assignment, you will write C code that performs recursion. For the purpose of this assignment, you will keep all functions in a single source file main.c. Your main job is to write a recursive function that generates and prints all possible password combinations using characters in an array. In your main() function you will first parse the command line arguments. You can assume that the arguments will always be provided in the correct format. Remember that the...
In this programming assignment, you will write C code that performs recursion. For the purpose of...
In this programming assignment, you will write C code that performs recursion. For the purpose of this assignment, you will keep all functions in a single source file main.c. Your main job is to write a recursive function that generates and prints all possible password combinations using characters in an array. In your main() function you will first parse the command line arguments. You can assume that the arguments will always be provided in the correct format. Remember that the...
Programming language is in python 3 For this project, you will import the json module. Write...
Programming language is in python 3 For this project, you will import the json module. Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. It just needs to read a local JSON file - it doesn't need to access the internet. Specifically, your class should have an init method that reads the file, and it should have a method named search_nobel that takes as parameters a...
Programming language is python 3 For this project, you will import the json module. Write a...
Programming language is python 3 For this project, you will import the json module. Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. The...
GPA calculator in C language To understand the value of records in a programming language, write...
GPA calculator in C language To understand the value of records in a programming language, write a small program in a C-based language that uses an array of structs that store student information, including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,” etc.). Note:Code and Output Screenshots
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT