Question

In: Computer Science

The Programming Language is C++ PLEASE, Make sure to read the requirements and grading criteria for...

The Programming Language is C++

PLEASE, Make sure to read the requirements and grading criteria for homework first... Thank you!!!

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

Summary :

Provided Notes , Code , Flowchart and output.

Notes :

Utilized typedef for the main student data and same can be done for other arrays as well.

Since the size is not defined , while declaring the data variable , need to provide the actual definition or else one can declare a very large array and utilize the count to keep track .

Further introduced 2 functions getLines() - which returns the number of students and printSUmmary() which prints the data in desired output format.

################## COde ####################

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

typedef int scores[][4] ;

// Function to get the count of lines 
int getLines()
{
        // initilize num lines to 0 
        int numLines = 0 ;
        // Open the file read line 
        string line ;
        ifstream ifile( "pr2data.txt");
        while ( getline(ifile,line) )
                numLines += 1;
        
        return numLines ;
        
}

void Setdata(scores data,int count )
{
        int i = 0 ;
        // open the file 
        ifstream ifile( "pr2data.txt");
        if ( ifile )
        {
                // while not reach eof read 
                while( !ifile.eof() )
                {
                        // this is required otherwise the last line is read twice 
                        if ( ifile.eof()) break;
                        ifile >> data[i][0] >> data[i][1] >> data[i][2] >> data[i][3] ;
                        i++ ;
                }
                
        } else 
        {
                cout << "\n Error opening pr2data.txt \n" ;
        }
}

// The student avg is stored in avg array 
void findstavg (scores data, double avg[] , int count )
{
        // iterate over the student scores and calculate avg 
        for( int i=0; i< count ; i++ )
        {
                avg[i] = (double) ( data[i][1] + data[i][2] + data[i][3] )*1.0 / 3.0 ;
        }
}

// Finds the avg of given Quicz ( row ) 
float Findqzavg(scores data, int row, int count )
{
        double avg = 0.0;
        // Iterate over the scores and calculate avg of only the quiz number 
        for(int i=0 ; i < count ; i++ )
        {
                avg += data[i][row];
        }
        
        return avg/count ;
}

// Finds the max of Quilz number 
int Findhigh (scores data, int row, int count  )
{
        int max = 0 ;
        // Iterate over the Quiz scores and find max 
        for ( int i=0 ; i < count ; i++ )
        {
                if ( data[i][row] > max )
                        max = data[i][row];
        }
        
        return max;
}


int Findlow (scores data, int row, int count  )
{
        int min = 10000 ;
        // Iterate over the Quiz scores and find min
        for ( int i=0 ; i < count ; i++ )
        {
                if ( data[i][row] < min )
                        min = data[i][row];
        }
        
        return min;
}
        

// This function prints the summary to the file 
void printSummary(scores data, double avgs[] , int count )
{
        // open the file 
        ofstream outfile;
    outfile.open("pr2data_out.txt");
        
        // Print heading 
        outfile << setw(9) << "    Student" 
                 << setw(9) << "Quiz 1"
                 << setw(9) << "Quiz 2"
                 << setw(9) << "Quiz 3"
                 << setw(12) << "   Average\n";
                 
        // Print student scores with avg 
        for( int i=0 ; i < count ; i++ )
        {
                outfile << setw(9) << data[i][0] 
                 << setw(9) << data[i][1]
                 << setw(9) << data[i][2]
                 << setw(9) << data[i][3]
                 << setw(12) << fixed << setprecision(2)  << (double)avgs[i] * 1.0 << "\n";
        
        }

        // Print High , Low and Avg scores 
        
        outfile << " High score" << setw(7) << Findhigh(data,1,count)
                                                << setw(9) << Findhigh(data,2,count)
                                                << setw(9) << Findhigh(data,3,count) << "\n";
        
        outfile << " Low score " << setw(7) << Findlow(data,1,count)
                                                << setw(9) << Findlow(data,2,count)
                                                << setw(9) << Findlow(data,3,count) << "\n";
        
        outfile << " Quiz Average " << setw(7) << fixed << setprecision(2) << Findqzavg(data,1,count)
                                                << setw(9) << fixed << setprecision(2) << Findqzavg(data,2,count)
                                                << setw(9)  << fixed << setprecision(2)<< Findqzavg(data,3,count) << "\n";
        
        outfile.close();

}


int main()
{
        
        int student_count = getLines() ;
        //cout << " Student Count " << student_count << "\n";
        // one can utilize type def here to delcare very large array at the begining and only use the count 
        int data[student_count][4] ;

        double student_avgs[student_count];
        
        Setdata(data,student_count);
        findstavg(data,student_avgs,student_count);

        printSummary(data,student_avgs,student_count);
}

Flowchart

Output :


Related Solutions

Please Use C language to Make a calculator. Make sure calculator is able to take up...
Please Use C language to Make a calculator. Make sure calculator is able to take up to 5 values. Try to make calculator using simple coding As you can. Please create a simple calculator with only +, -,* and divide. It has to be able to enter any numbers (including decimals) and be able to do the following functions: +, -, divide and multiply. Please have the answers, always rounded to two decimal figures. The calculator will also have to...
C++ Please read the question carefully and make sure that the function prototypes given are used...
C++ Please read the question carefully and make sure that the function prototypes given are used correctly for both parts. This is one whole programming assignment so please make sure that it;s answered entirely not just one part. The output example is provided at the end of the question. First , write a program to create an array and fill it up with 20 randomly generated integers between 0 to 10 and output the array. Part 1: Write a function...
Be sure to use only C for the Programming Language in this problem. Before we start...
Be sure to use only C for the Programming Language in this problem. Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below. Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up...
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to input 2 numbers, a starting number x and ending number y Implements a while loop that counts from x (start) to y(end). Inside the loop, print to the screen the current number Print rather the current number is even or odd If the number is even , multiply by the number by 3 and print the results to the screen. If the number is...
Code in C++ programming language description about read and write data to memory example.
Code in C++ programming language description about read and write data to memory example.
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...
Instructions: 1. Please use only C as the language of programming. 2. Please submit the following:...
Instructions: 1. Please use only C as the language of programming. 2. Please submit the following: (1) the client and the server source files each (2) a brief Readme le that shows the usage of the program. 3. Please appropriately comment your program and name all the identifiers suitable, to enable enhanced readability of the code. Problem: Write an ftp client and an ftp server such that the client sends a request to ftp server for downloading a file. The...
Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the...
Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the console input and create a file. ['$' character denotes end of content in file.] Close the file after creation. Now encrypt the text file using Caesar Cipher (Use key value as 5). Display the contents of the updated file. #include <iostream> using namespace std; int main() { // write code here }
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT