Question

Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a students name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the students grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88 5 English II 100 3 Psychology 68 3 Write a complete C++ program to compute the GPA for the student. uirements: Use a two-dimensional char array for the course names, with one course a student may take at most 10 courses per semester. Use a parallel two- name per row; dimensional array with each row (which corresponds to a course) having three columns containing, respectively, the course grade average (input), the course credits (input) and the course GPA points (to be computed) The GPA points for a course is the product of grade value (A is 4, B is 3, C is 2, D is 1, F is 0) times course credits. (sum of GPA points) (sum of course credits) Semester GPA is Note: The grade average, number of course credits, and the GPA points can all be integers, but the GPA value must be decimal, and is to be output with 4 decimal places. Function and output requirements: One function does input. One function computes the course GPA points in the array. One function computes the GPA. One function outputs to a file the students name, a table of the courses, grade rececived, course credits and GPA points earned. and finally, the students semester GPA.


0 0
Add a comment Improve this question Transcribed image text
Answer #1


//below is code written in C++ to perform as per the requirement.

//NOTE:1 Please note that the below programs have been tested on ubuntu 14.04 system and compiled under g++ compiler. This code will also work on other IDE's.

// C++ code
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;

int size = 0;

void input(char**, float**, char*);
void output(char**, float** , char* , float, char*);
int compute_gpa(float**, char*);

int main(){

char* studentName;
char* grades = new char[10];
char **nameCOurse = new char*[10];
float **metrics = new float*[10];
float GPA;

for(int i=0; i<10; i++){
metrics[i] = new float[3];
}

input(nameCOurse, metrics, studentName);
GPA = compute_gpa(metrics, grades);

output(nameCOurse, metrics,studentName, GPA, grades);

cout << "Results written to output.txt\n";
return 0;
}

void input(char **nameCOurse, float **metrics, char* studentName){
int i = 0;
ifstream inFile;
inFile.open("input.txt");

studentName = new char[256];
inFile.getline(studentName, 100);
nameCOurse[i] = new char[256];
string line;
while(inFile.getline(nameCOurse[i], 1000)){
inFile >> metrics[i][0] >> metrics[i][1];
nameCOurse[++i] = new char[256];
inFile.ignore();
}

size = i;
}

int compute_gpa(float **metrics, char* grades){

float sum_of_gpa = 0;
float sum_of_cre = 0;

for(int i=0; i< size; i++){
if(metrics[i][0] >= 90 && metrics[i][0] <= 100){
metrics[i][2] = metrics[i][1]*4;
grades[i] = 'A';
}
else if(metrics[i][0] >= 80 && metrics[i][0] <= 89){
metrics[i][2] = metrics[i][1]*3;
grades[i] = 'B';
}
else if(metrics[i][0] >= 70 && metrics[i][0] <= 79){
metrics[i][2] = metrics[i][1]*2;
grades[i] = 'C';
}
else if(metrics[i][0] >= 60 && metrics[i][0] <= 69){
metrics[i][2] = metrics[i][1];
grades[i] = 'D';
}
else if(metrics[i][0] >= 0 && metrics[i][0] <= 59){
metrics[i][2] = 0;
grades[i] = 'F';
}
else{
cout << "Wrong Input";
}

sum_of_gpa = sum_of_gpa + metrics[i][2];
sum_of_cre = sum_of_cre + metrics[i][1];
}

return sum_of_gpa/sum_of_cre;
}

void output(char** nameCOurse, float** metrics, char* studentName, float GPA, char* grades)
{
ofstream outFile("output.txt");

outFile.setf(ios::left, ios::adjustfield);
outFile.width(10);
outFile << "Course";
outFile.setf(ios::left, ios::adjustfield);
outFile.width(7);
outFile << "Grades";
outFile.setf(ios::left, ios::adjustfield);
outFile.width(7);
outFile << "GPA";
outFile.setf(ios::left, ios::adjustfield);
outFile.width(7);
outFile << "Credits\n";


for(int i=0; i< size; i++){
outFile.setf(ios::left, ios::adjustfield);
outFile.width(10);
outFile << nameCOurse[i];
  
outFile.setf(ios::left, ios::adjustfield);
outFile.width(7);
outFile << grades[i];

outFile.setf(ios::left, ios::adjustfield);
outFile.width(7);
outFile << metrics[i][2];

outFile.setf(ios::left, ios::adjustfield);
outFile.width(7);
outFile << metrics[i][1] << "\n";
}


outFile.precision(4);
outFile << "Semester GPA : " << GPA << endl;
outFile.close();

return;
}


input.txt
Jon P. Washington, Jr.
Computer Science I
81 4
PreCalculus
75 3
Biology I
88 5
English II
100 3
Psychology I
68 3

output.txt
Course Grades GPA Credits
Computer Science IB 12 4
PreCalculusC 6 3
Biology I B 15 5
English IIA 12 3
Psychology ID 3 3
Semester GPA : 2



Terminal 四 1回(2:47, 72%) 11:16 AM ※ubuntu new. py new.cpP input.txt output.txt nums.txt songs.dat 2 I/below is code written i

Add a comment
Know the answer?
Add Answer to:
Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • Please help me to write a program in C++ with comments and to keep it simple...

    Please help me to write a program in C++ with comments and to keep it simple as possible. Also, post the output please. Thank you! Here is input data: 2333021 BOKOW, R. NS201 3 A 2333021 BOKOW, R. MG342 3 A 2333021 BOKOW, R. FA302 1 A 2574063 FALLIN, D. MK106 3 C 2574063 FALLIN, D. MA208 3 B 2574063 FALLIN, D. CM201 3 C 2574063 FALLIN, D. CP101 2 B 2663628 KINGSLEY, M. QA140 3 A 2663628 KINGSLEY, M....

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • 12.8 GPA reports using files This program is to compute and write to a file the...

    12.8 GPA reports using files This program is to compute and write to a file the GPA for student scores read from an input file. As in Lab 7.5, the point values of the grades are 4 for A, 3 for B, 2 for C, 1 for D, and 0 for F. Except for the grade A, where + has no effect, a + after the letter increases the point value by 0.3, and except for F, where a -...

  • Hello I need help fixing my C++ code. I need to display in the console the...

    Hello I need help fixing my C++ code. I need to display in the console the information saved in the file as well have the content saved in the file output in a fixed position like the screenshot. Thanks. CODE #include<iostream> #include<fstream> #include<iomanip> using namespace std; //main function int main() {    //variable to store student id    int id;       //variables to store old gpa(ogpa), old course credits(occ), new course credits(ncc), current gpa(cur_gpa), cumulative gpa(cum_gpa)    float ogpa,...

  • Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written...

    Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...

  • (7) Student grade point statistics [Problem description] There is a need to make statistics of the grade points o...

    (7) Student grade point statistics [Problem description] There is a need to make statistics of the grade points of the students in the first semester of 2018. It is assumed that there are n (can be set as 6) classes in this grade, and there are 20 students in each class, the total number of courses with exam is m (can be set as 10), and the percentage system is adopted for each course. The gpa is 4, 3, 2,1,...

  • Write a C++ program to store and update students' academic records in a binary search tree....

    Write a C++ program to store and update students' academic records in a binary search tree. Each record (node) in the binary search tree should contain the following information fields:               1) Student name - the key field (string);               2) Credits attempted (integer);               3) Credits earned (integer);               4) Grade point average - GPA (real).                             All student information is to be read from a text file. Each record in the file represents the grade information on...

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • 12.8 GPA reports using files Prompt the user by "Enter name of input file: " for...

    12.8 GPA reports using files Prompt the user by "Enter name of input file: " for the name of an input file and open that file for reading. The two input files for the tests are already at the zyBooks site.They each have a list of student names with the course they have taken, of the form Jacobs, Anthony ECS10 4 B- ECS20 4 C+ ANS17 3 A ANS49H 2 D Wilson, Elaine ECS10 4 B+ ECS20 4 C+ ANS17...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT