Question
I am facing some errors in the code of mine in the object oriented programming.Please help me out with solving of those errors. Here are
I am facing some errors in the code of mine in the object oriented programming.Please help me out with solving of those errors. Here are the files for the codes
1 .) main.cpp
#include
#include "GPAlist.h"
using namespace sdds;
int main() {
if (gpaQuery("std.csv")) {
std::cout << "This should have failed!" << std::endl;
}
else {
std::cout << "failed!, this is the correct exectution" << std::endl;
}
if (!gpaQuery("students.csv")) {
std::cout << "This should have worked, fix the problem!" << std::endl;
}
std::cout << "Goodbye!" << std::endl;
return 0;
}
File No 2.) GPA.h
#ifndef SDDS_GPA_H
#define SDDS_GPA_H
namespace sdds {
struct GPA {
char name[116];
double gpa;
int stno;
};
}
#endif // !SDDS_GPA_H
File no 3.) GPAlist.cpp
bool sdds::gpaQuery(const char* filename)
{
ifstream dataFile(filename);
if (!dataFile.is_open())
{
cout << "Unable to open file!" << endl;
return false;
}
else {
// read the data from the file and
// store it in an array of GPA structs
allGPA[100];
int count = 0;
while (dataFile.good())
{
dataFile >> allGPA[count].name;
dataFile >> allGPA[count].stno;
dataFile >> allGPA[count].gpa;
count++;
}
// now call the UI module to prompt the user
// for input and perform the query
return UI_query(allGPA, count);
return 0;
}
}
File no 4.) GPAlist.h
#ifndef SDDS_GPAlist_H_
#define SDDS_GPAlist_H_
#include
#include "GPA.h"
namespace sdds {
bool gpaQuery(const char* filename);
};
#endif // SDDS_GPAlist_H_
File no 5.) File.cpp
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include "File.h"
#include
using namespace std;
using namespace sdds;
int main() {
{
bool readData(GPA & gpa, std::ifstream & dataFile) {
dataFile >> gpa.name;
dataFile >> gpa.stno;
dataFile >> gpa.gpa;
return dataFile.good();
}
int countRecords(std::ifstream & dataFile) {
int count = 0; GPA dummy;
while (readData(dummy, dataFile)) {
count++;
}
return count;
}
return 0;
}
File no 6.) File.h
#ifndef SDDS_File_H_
#define SDDS_File_H_
#include
#include "GPA.h"
namespace sdds {
bool readData(GPA& gpa, std::ifstream& dataFile);
int countRecords(std::ifstream& dataFile);
};
#endif // SDDS_File_H_
File no 7.) UI.cpp
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include "UI.h"
using namespace std;
using namespace sdds;
int main() {
bool compare_gpa(GPA g1, GPA g2) {
if (g1.gpa == g2.gpa) {
return g1.stno < g2.stno;
}
return g1.gpa < g2.gpa;
}
// sort the array of GPA using selection sort
void sortGPA(GPA * allGPA, int count) {
for (int i = 0; i < count; i++) {
int minIdx = i;
for (int j = i + 1; j < count; j++) {
if (compare_gpa(allGPA[j], allGPA[minIdx]))
{
minIdx = j;
}
}
GPA temp = allGPA[i];
allGPA[i] = allGPA[minIdx];
allGPA[minIdx] = temp;
}
}
bool UI_query(GPA * allGPA, int count) {
// sort the array of GPA
sortGPA(allGPA, count);
char op[2];
float val;
int i;
// prompt the user for input
while (true) {
std::cout << "? ";
std::cin >> op;
if (op[0] == '!') {
return true;
}
std::cin >> val;
for (i = 0; i < count; i++) {
if ((op[0] == '<' && allGPA[i].gpa < val) || (op[0] == '>' && allGPA[i].gpa > val) || (op[0] == '~' && abs(allGPA[i].gpa - val) < 0.05))
{
std::cout << "[" << i + 1 << "] " << allGPA[i].stno << ": " << allGPA[i].gpa << " (" << allGPA[i].name << ")" << std::endl;
}
}
}
}
File no 8.) UI.h
#ifndef SDDS_UI_H_
#define SDDS_UI_H_
#include
#include "GPA.h"
namespace sdds {
int count;
bool UI_query(GPA* allGPA, int count);
};
#endif // SDDS_UI_H_
The data file is named as students.csv
Data File students.csv
Abraham Simpson,324543,3.9
Agnes Skinner,470546,4.0
Akira Kurosawa,411928,2.1
Alice Glick,459608,3.3
Allison Taylor,747954,2.3
Apu Nahasapeemapetilon,290816,4.0
Artie Ziff,245446,3.6
Baby Gerald,155387,3.9
Barney Gumble,262592,1.7
Bart Simpson,753102,1.8
Bernice Hibbert,242653,3.9
Brandine Spuckler,584416,1.7
Bumblebee Man,603577,3.1
Carl Carlson,241968,3.0
Chazz Busby,362030,3.7
Cletus Spuckler,653783,2.9
Comic Book Guy,234272,3.7
Dewey Largo,910346,2.5
Disco Stu,736389,4.0
Dolph Starbeam,829982,3.9
Drederick Tatum,937537,2.3
Edna Krabappel,877842,1.6
Elizabeth Hoover,389470,3.5
Gil Gunderson,383513,1.7
Gloria Jailbird,601956,3.2
Groundskeeper Willie,774965,2.8
Hans Moleman,217944,2.3
Helen Lovejoy,686009,1.8
Herman Hermann,164996,2.2
Homer Simpson,413084,2.1
Jacqueline Bouvier,522856,2.3
Janey Powell,919159,2.2
Jasper Beardly,417008,3.6
Jessica Lovejoy,667331,1.9
Jimbo Jones,718588,3.6
Johnny Tightlips,840329,3.3
Judge Roy Snyder,533451,1.8
Kearney Zzyzwicz,758048,2.8
Kent Brockman,568727,1.7
Kirk Van Houten,695606,1.6
Krusty The Clown,901832,4.0
Kumiko Albertson,339422,3.5
Lenny Leonard,562762,2.6
Lindsey Naegle,570423,4.0
Ling Bouvier,249669,4.0
Lionel Hutz,212516,2.8
Lisa Simpson,693664,2.3
Luann Van Houten,737447,2.7
Luigi Risotto,757705,2.5
Lunchlady Doris,895470,3.0
Maggie Simpson,712478,3.1
Manjula Nahasapeemapetilon,236261,2.3
Marge Simpson,695580,3.1
Martin Prince,575687,2.3
Maude Flanders,272754,2.3
Mayor Joe Quimby,425163,3.0
Milhouse Van Houten,619711,2.9
Miss Springfield,855862,3.5
Moe Szyslak,219634,3.2
Mona Simpson,419417,3.4
Ned Flanders,746703,2.5
Nelson Muntz,584760,2.4
Old Jewish Man,259301,2.3
Patty Bouvier,544545,3.1
Rabbi Hyman Krustofsky,374366,3.5
Rainier Wolfcastle,674248,2.7
Ralph Wiggum,414067,3.5
Rod Flanders,823458,2.5
Roger Meyers Jr.,313590,2.1
Ruth Powers,231018,3.7
Sarah Wiggum,920562,2.3
Sea Captain,544294,3.7
Selma Bouvier,217994,3.8
Seymour Skinner,434336,1.7
Shauna Chalmers,828516,2.1
Sideshow Mel,799960,2.9
Snake Jailbird,950955,1.8
Squeaky-Voiced Teen,194002,1.8
Surly Duff,146127,3.4
The Rich Texan,300288,2.8
Todd Flanders,257297,2.3
Troy McClure,394769,1.9
Uter Zorker,712465,2.2
Waylon Smithers,387433,3.0
Wendell Borton,677806,1.7
Wise Guy,134681,1.8
The output needed is as below:
Enter GPA query...
? @2.2
Syntax error: ? [Op][value]
Op: [>,<,~,!]
value: GPA value
? ~3.7
[1] 231018: 3.7 (Ruth Powers)
[2] 234272: 3.7 (Comic Book Guy)
[3] 362030: 3.7 (Chazz Busby)
[4] 544294: 3.7 (Sea Captain)
? ~3.8
[1] 217994: 3.8 (Selma Bouvier)
? <2.0
[1] 134681: 1.8 (Wise Guy)
[2] 194002: 1.8 (Squeaky-Voiced Teen)
[3] 262592: 1.7 (Barney Gumble)
[4] 383513: 1.7 (Gil Gunderson)
[5] 394769: 1.9 (Troy McClure)
[6] 434336: 1.7 (Seymour Skinner)
[7] 533451: 1.8 (Judge Roy Snyder)
[8] 568727: 1.7 (Kent Brockman)
[9] 584416: 1.7 (Brandine Spuckler)
[10] 667331: 1.9 (Jessica Lovejoy)
[11] 677806: 1.7 (Wendell Borton)
[12] 686009: 1.8 (Helen Lovejoy)
[13] 695606: 1.6 (Kirk Van Houten)
[14] 753102: 1.8 (Bart Simpson)
[15] 877842: 1.6 (Edna Krabappel)
[16] 950955: 1.8 (Snake Jailbird)
? >3.8
[1] 155387: 3.9 (Baby Gerald)
[2] 242653: 3.9 (Bernice Hibbert)
[3] 249669: 4.0 (Ling Bouvier)
[4] 290816: 4.0 (Apu Nahasapeemapetilon)
[5] 324543: 3.9 (Abraham Simpson)
[6] 470546: 4.0 (Agnes Skinner)
[7] 570423: 4.0 (Lindsey Naegle)
[8] 736389: 4.0 (Disco Stu)
[9] 829982: 3.9 (Dolph Starbeam)
[10] 901832: 4.0 (Krusty The Clown)
? ~3.9
[1] 155387: 3.9 (Baby Gerald)
[2] 242653: 3.9 (Bernice Hibbert)
[3] 324543: 3.9 (Abraham Simpson)
[4] 829982: 3.9 (Dolph Starbeam)
? !
Exit the program? (Y)es/(N)o: y
Goodbye!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
It seems like there are several issues in the provided code Lets go through them one by one and fix ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started