Code in Visual Studio Code 2017. Use beginner C++ skills. Write a program to cal
ID: 3749559 • Letter: C
Question
Code in Visual Studio Code 2017. Use beginner C++ skills.
Write a program to calculate the current semester's grade point average and the cumulative grade point average of a student. The program should use an input data file to 1. read the student's six-digit identification number (id ), his/her old grade point average (), and the old number of course credits (occ) 2. read the course credits (cl, c2, c3, c4) and grades (gl, g2, g3, g4) for each of four courses 3. compute: old number of honor points-ohp-occ x ogpa new number of honor points-nhp-clxgl + c2xg2+c3xg3 + c4 x g4 total number of new course creditsncc-cl +c2+ c3 c4 current GPA- cur gpa-nhp/ncc cumulative GPA -cum gpa-(nhp ohp)/(ncc occ) The input data file should be created such that id, ogpa, and occ are placed on the first line, cl, c2, c3, and c4 are listed on the second line, and gl, g2, g3, and g4 are listed on the third line; as an example, the input file could contain the following data 24 4 213141 3.2 4 4 4 All outputs should be written to an output file which has a format exactly like the following Student ID number 213141 Previous semesters' credit Previous semesters' GPA GPA of current semester Cumulative GPA: Total credits completed 24 3.2 3.7 38Explanation / Answer
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{
filebuf fb,fb1;
fb.open ("test.txt",ios::in);
fb1.open("op.txt",ios::out);
ostream os(&fb1);
istream is(&fb);
char *str;
String data="";
is.getline(str,13,' ');
string id="";
string ogpa,occ;
ogpa=occ="";
for(int i=0;i<6;i++)
{
id = id + str[i];
}
for(int i=8;i<10;i++)
{
ogpa += str[i];
}
for(int i=11;i<13;i++)
{
occ += str[i];
}
char *line2;
is.getline(line2,8,' ');
string c1,c2,c3,c4;
c1=c2=c3=c4="";
c1+=line2[0];
c1+=line2[2];
c1+=line2[4];
c1+=line2[6];
char *line3;
is.getline(line3,8,' ');
string g1,g2,g3,g4;
g1=g2=g3=g4="";
g1+=line3[0];
g1+=line3[2];
g1+=line3[4];
g1+=line3[6];
double ohp,occ1,ogpa1;
occ1 = strtod(occ,' ');
ogpa11 = strtod(ogpa,' ');
ohp = occ*ogpa;
double c11,c21,c31,c41,g11,g21,g31,g41,nhp,ncc,cur_gpa,cum_gpa;
c11 = strtod(c1,' ');c21 = strtod(c2,' ');c31 = strtod(c3,' ');c41 = strtod(c4,' ');
g11 = strtod(g1,' ');g21 = strtod(g2,' ');g31 = strtod(g3,' ');g41 = strtod(g4,' ');
nhp = c11*g11 + c21*g21 + c31*g31 + c41*g41;
ncc = c11+c21+c31+c41;
cur_gpa = nhp/ncc;
cum_gpa = (nhp+ohp)/(ncc+occ);
string cur_gpa1="";
string cum_gpa1="";
string ncc1="";
sprintf(cur_gpa1,"%f",cur_gpa);
sprintf(cum_gpa1,"%f",cum_gpa);
sprintf(ncc,"%f",ncc);
String data=""
data+="Student ID number :"+id+" ";
data+="Previous semesters' credit:"+occ+" ";
data+="Previous semesters' GPA :"+ogpa+" ";
data+="GPA of current semester :"+cur_gpa1+" ";
data+="Cumulative GPA :"+cum_gpa1"+" ";
data+="Total credits completed"+ncc1+" ";
os.write(data,500);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.