Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello! I want to know that is the correct coding for that to submit!! Please let me know^^ Thank you! Correct output Enter GPA query...

Hello!

I want to know that is the correct coding for that to submit!! Please let me know^^ Thank you!

Correct output

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!

GPA.h

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!

main.cpp

/*********************************************************************** // Workshop 1 p2: tester program // // File main.cpp // Version 1.0 // Date winter 2023 // Author Fardad Soleimanloo // // // Revision History // ----------------------------------------------------------- // Name Date Reason ///////////////////////////////////////////////////////////////// ***********************************************************************/ #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; }

w1p1.cpp

#define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std;

struct Movie { char m_title[128]; int m_year; char m_rating[6]; int m_duration; char m_genres[10][11]; float m_consumerRating; };

FILE* fptr; Movie movies[50];

bool loadMovies(); bool hasGenre(const Movie* mvp, const char genre[]); void displayMovie(const Movie* mvp); void displayMoviesWithGenre(const char genre[]); bool openFile(const char filename[]); void closeFile(); bool readTitle(char title[]); bool readYear(int* year); bool readMovieRating(char rating[]); bool readDuration(int* duration); bool readGenres(char genres[][11]); bool readConsumerRating(float* rating); void flushkeys(); bool yes();

int main() { bool done = false; char genre[128]; loadMovies(); cout << "Welcome to 50 top movies of all times \"genre\" search." << endl << endl; while (!done) { cout << "Enter the movie genre to start the search: "; cin >> genre; flushkeys(); displayMoviesWithGenre(genre); cout << "Do another search? (Y)es: "; done = !yes(); cout << endl; } cout << "Goodbye!" << endl; return 0; }

// flushes the keyboard void flushkeys() { while (cin.get() != ' '); }

// returns true if user enter y or Y bool yes() { char ch = cin.get(); flushkeys(); return ch == 'y' || ch == 'Y'; }

// loads all the moves into the global array of structures. bool loadMovies() { Movie mv; int mnum = 0; // number of movies read bool ok = true; if (openFile("movies.dat")) { while (ok && mnum < 50) { ok = readTitle(mv.m_title) && readYear(&mv.m_year) && readMovieRating(mv.m_rating) && readDuration(&mv.m_duration) && readGenres(mv.m_genres) && readConsumerRating(&mv.m_consumerRating); if (ok) movies[mnum++] = mv; } closeFile(); } return mnum == 50; }

// returns true is the genre arg is substring of any of the // genres of the target of the mvp (Movie*) arg. bool hasGenre(const Movie* mvp, const char genre[]) { int i = 0; bool found = false; while (!found && mvp->m_genres[i][0]) { if (strstr(mvp->m_genres[i++], genre)) { found = true; } } return found; }

// displays the movie info void displayMovie(const Movie* mvp) { int i = 1; cout << mvp->m_title << " [" << mvp->m_year << "], " << mvp->m_rating << ", duration: " << mvp->m_duration << " minutes, Rating: " << mvp->m_consumerRating << "/10" << endl << " (" << mvp->m_genres[0]; while (mvp->m_genres[i][0]) { cout << ", " << mvp->m_genres[i++]; } cout << ")" << endl; }

// displays all the movies containing the genre arg void displayMoviesWithGenre(const char genre[]) { int i, j; for (i = 0, j = 1; i < 50; i++) { if (hasGenre(&movies[i], genre)) { cout << j++ << "- "; displayMovie(&movies[i]); } } if (j == 1) { cout << "No match found for: " << genre << endl; } }

// opens the data file and returns true is successful bool openFile(const char filename[]) { fptr = fopen(filename, "r"); return fptr != NULL; }

// closes the data file void closeFile() { if (fptr) fclose(fptr); }

// reads the title of the movie from the global fptr File pointer // returns true if successful bool readTitle(char title[]) { return fscanf(fptr, "%[^(](", title) == 1; }

// reads the year of the movie from the global fptr File pointer // returns true if successful bool readYear(int* year) { return fscanf(fptr, "%d)", year) == 1; }

// reads the year of the movie from the global fptr File pointer // returns true if successful bool readMovieRating(char rating[]) { return fscanf(fptr, " %[^|]|", rating) == 1; }

// reads the duration of the movie from the global fptr File pointer // returns true if successful bool readDuration(int* duration) { return fscanf(fptr, "%d|", duration) == 1; }

// reads the genras of the movie from the global fptr File pointer // returns true if successful bool readGenres(char genre[][11]) { char genres[256]; int gi = 0; //genres index; int i = 0;// genre[i] index int j = 0;// genre[i][j] index bool res = fscanf(fptr, " %[^|]|", genres); if (res) { //spreading csv to array of strings res = false; while (genres[gi]) { if (genres[gi] != ',') { genre[i][j++] = genres[gi++]; res = true; } else { genre[i][j] = '\0'; i++; gi++; j = 0; } } } genre[i++][j] = '\0'; genre[i][0] = '\0'; // NULL terminating the array of strings return res; }

// reads the consumerRating of the movie from the global fptr File pointer // returns true if successful bool readConsumerRating(float* rating) { return fscanf(fptr, "%f ", rating) == 1; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

Have you got a one page summary that you are happy with?

Answered: 1 week ago