#include #include #include using namespace std; struct Student{ string firstName; string lastName; string studentId; double gpa; }; class MyClass{ public: unordered_map classHoursInfo; vector students; unordered_map creditValue = {{"A", 4}, {"B", 3}, {"C", 2}, {"D", 1}, {"F", 0}}; void readStudentData(string filepath){ cout << "reading student data \n"; ifstream inpStream(filepath); string text; string tmp[4]; while (getline (inpStream, text)) { string str = "", prevKey = ""; int j= 0; unordered_map curStudentClassInfo; for(int i=0; i3){ if(prevKey.length()==0){ curStudentClassInfo[str] = 0; prevKey = str; str.clear(); } else{ curStudentClassInfo[prevKey] = creditValue[str]; prevKey = ""; str.clear(); } } else{ tmp[j++] = str; str.clear(); } } else{ str = str+text[i]; } } if(str.length() != 0){ curStudentClassInfo[prevKey] = creditValue[str]; } double curGPA = gpacalculation(curStudentClassInfo, classHoursInfo); students.push_back({tmp[0], tmp[1], tmp[2], curGPA}); } inpStream.close(); } };   double gpacalculation(unordered_map < string,int> studentData, unordered_map creditData);{ cout << "calculating GPA of a student \n" int sumOfCreditHours = 0; int prod = 0; for (auto &x : studentData) { sumOfCreditHours += creditData[,first]; prod += ((x.second)*(creditData[x,first])); } return prod/(sumOfCreditHours+0.0); } void readCreditData(string filepath){ cout << "reading credit data \n"; ifstream inpStream(filepath); string text; string tmp[2]; while (getline (inpStream, text)) { string str = ""; int j= 0; for(int i=0; i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

#include <bits/stdc++.h>
#include<unordered_map>
#include <string>

using namespace std;

struct Student{
string firstName;
string lastName;
string studentId;
double gpa;
};

class MyClass{
public:
unordered_map<string, int>
classHoursInfo;
vector<Student> students;
unordered_map<string, int> creditValue = {{"A", 4}, {"B", 3}, {"C", 2}, {"D", 1}, {"F", 0}};

void readStudentData(string filepath){
cout << "reading student data \n";
ifstream inpStream(filepath);
string text;
string tmp[4];
while (getline (inpStream, text)) {
string str = "", prevKey = ""; int j= 0;
unordered_map<string, int> curStudentClassInfo;
for(int i=0; i<text.length(); i++){
if(isspace(text[i])){
if(j>3){
if(prevKey.length()==0){
curStudentClassInfo[str] = 0;
prevKey = str;
str.clear();
}
else{
curStudentClassInfo[prevKey] = creditValue[str];
prevKey = "";
str.clear();
}
}
else{
tmp[j++] = str;
str.clear();
}
}
else{
str = str+text[i];
}
}
if(str.length() != 0){
curStudentClassInfo[prevKey] = creditValue[str];
}
double curGPA = gpacalculation(curStudentClassInfo, classHoursInfo);
students.push_back({tmp[0], tmp[1], tmp[2], curGPA});
}
inpStream.close();
}
};

 

double gpacalculation(unordered_map < string,int> studentData, unordered_map<string,int> creditData);{
cout << "calculating GPA of a student \n"
int sumOfCreditHours = 0;
int prod = 0;
for (auto &x : studentData) {
sumOfCreditHours += creditData[,first];
prod += ((x.second)*(creditData[x,first]));
}
return prod/(sumOfCreditHours+0.0);
}

void readCreditData(string filepath){
cout << "reading credit data \n";
ifstream inpStream(filepath);
string text;
string tmp[2];
while (getline (inpStream, text)) {
string str = ""; int j= 0;
for(int i=0; i<text.length(); i++){
if(isspace(text[i])){
tmp[j++] = str;
str.clear();
}
else{
str = str+text[i];
}
}
if(j!=2) tmp[1] = str;
classHoursInfo[tmp(0)] = stoi(tmp(1));
}
inpStream.close();
}

void writeToFile(string filepath){
cout << "writing students GPA to ouput file and printing in console \n";
ofstream outStream(filepath);
for(Student s: students){
string data = s.firstName+" "+s.lastName+" "+s.studentId+" "+to_string(s.gpa)+"\n";
outStream<<data;
cout<<data;
}
outStream.close();
}
};

int main() {
MyClass c;
c.readCreditData("Credit.txt");
c.readStudentData("Student.txt");
c.writeToFile("StudentsGPA.txt");
}

 

Above is the code i have written but i am having 2 error which i have posted the images for it

Expert Solution
Step 1

1st error: You close the class before the gpacalculation function so that’s why code shows the error.

2nd error: you close the class before int main() and also close the class before gpaclaculation() that’s why it shows this ‘{‘ error.

 

I have closed the class after writetofile() function this resolved both errors.

 

 

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education