Question

In: Computer Science

In the program the "case: 'C'" doesn't seem to function correctly, We were told to write...

In the program the "case: 'C'" doesn't seem to function correctly,

We were told to write a book tracking program, and it takes inputs and once all the book info such as ISBN, date, author, course number, etc are put in then input, then we can print them out, by using the print functions that are defined in the program. Example:

the formats are as follows, when defining the book: "B-ISBN-TITLE"

So then in the terminal once the code compiles I can input: "B 1234567890123 Title of book"

and thus that book is defined, and I needed to make the code print the books info out and it's format were "GB-ISBN"

So then in the terminal after the book is defined I can type "GB 1234567890123" and the isbn and books title will be printed out that were define above.

NOW my problem is with the C which defines a course and it's format is "C-Department Code-Course Number-Name"

So if type "C CSEC 215 Name of the course" it should store it, until I use the print function "PC" which will print out the course that are defined. BUT I am getting an "abort message, out of range", and it points the error at the "case: C" switch statement in the code.

Can someone take a look at the code and help me figure out the solution,

Here is the code:

#include
#include
#include
#include
using namespace std;


int bookCounter = 0, courseCounter = 0, classCounter = 0;

struct Book
{
long isbn;
string title;
string author;
int edition;
string publicationDate;
double newRate = -1;
double usedRate = -1;
double rentedRate = -1;
double eRate = -1;
}* books[100];

struct Course
{
int deptCode;
int courseNumber;
string name;

}*course[100];

struct Class
{
struct Book *book;
struct Course *course;
int sectionNumber;
bool required;
}*classes[100];


int getBook( long newISBN)
{
for(int i=0; i {
if(books[i]->isbn == newISBN)
{
return i;
}
}
return -1;
}

int getCourse(int courseNum, int dept)
{
for(int i=0; i {
if(course[i]->courseNumber == courseNum && course[i]->deptCode == dept)
{
return i;
}
}
return -1;
}

void printBooks(string code, istringstream &iss)
{
int deptCode, sectionNum, courseNum;
long isbn;
if(code == "GC") iss>>deptCode>>courseNum;
else if(code=="GS") iss>>deptCode>>courseNum>>sectionNum;
else if(code == "GB") iss>>isbn;
for(int i=0; i {
if(code=="GB" && classes[i]->book->isbn==isbn)
{
coutisbn<<" "title<<" ";
if(classes[i]->required)
cout<<"Required\n";
else cout<<"Optional\n";
}
else if(classes[i]->course->courseNumber == courseNum && classes[i]->course->deptCode == deptCode)
{
if(code=="GS" && classes[i]->sectionNumber == sectionNum)
{
coutisbn<<" "title<<" ";
if(classes[i]->required)
cout<<"Required\n";
else cout<<"Optional\n";
}
if(code == "GC")
{
coutisbn<<" "title<<" ";
if(classes[i]->required)
cout<<"Required\n";
else cout<<"Optional\n";
}
}
}
}


void printAllInfo(string code, istringstream &iss)
{
if(code == "PB")
{
for(int i=0; i {
cout

if(classes[i]->course->deptCode==deptCode)
{
coutisbn<<" "title<<"\n";
}
}
}
else if(code == "PY")
{
int pmonth, pyear, checkMonth, checkYear;
int ch;
iss>>checkMonth>>ch>>checkYear;

for(int i=0; i {
istringstream isstreamer(books[i]->publicationDate);
isstreamer>>pmonth>>ch>>pyear;
if((pyear==checkYear && pmonth>checkMonth)||(pyear>checkYear))
{
cout

Solutions

Expert Solution

I have improved code as much as I could but there is no switch block as mentioned in question.

Here is code after fixing several issues but still incomplete. Please share full code.

#include
#include
#include
#include
using namespace std;

int bookCounter = 0, courseCounter = 0, classCounter = 0;

struct Book
{
long isbn;
string title;
string author;
int edition;
string publicationDate;
double newRate = -1;
double usedRate = -1;
double rentedRate = -1;
double eRate = -1;
}* books[100];

struct Course
{
int deptCode;
int courseNumber;
string name;
}*course[100];

struct Class
{
struct Book *book;
struct Course *course;
int sectionNumber;
bool required;
}*classes[100];

int getBook( long newISBN)
{
for(int i=0; i < bookCounter; i++)
{
if(books[i]->isbn == newISBN)
{
return i;
}
}
return -1;
}
int getCourse(int courseNum, int dept)
{
for(int i=0; i < courseCounter; i++)
{
if((course[i]->courseNumber == courseNum) && (course[i]->deptCode == dept))
{
return i;
}
}
return -1;
}

void printBooks(string code, string title, long isbn, int deptCode, int sectionNum, int courseNum, istringstream &iss)
{
/*
if(code == "GC")
iss>>deptCode>>courseNum;
else
if(code=="GS")
iss>>deptCode>>courseNum>>sectionNum;
else
if(code == "GB")
iss>>isbn;
*/
for(int i=0; i < classCounter; i++)
{
if(code=="GB" && classes[i]->book->isbn==isbn)
{
cout <<isbn<<" "<<title<<" ";
if(classes[i]->required)
cout<<"Required\n";
else
cout<<"Optional\n";
}
else
if(classes[i]->course->courseNumber == courseNum && classes[i]->course->deptCode == deptCode)
{
if(code=="GS" && classes[i]->sectionNumber == sectionNum)
{
cout << isbn << " " << title<<" ";
if(classes[i]->required)
cout<<"Required\n";
else
cout<<"Optional\n";
}
if(code == "GC")
{
cout << isbn<<" " << title<<" ";
if(classes[i]->required)
cout<<"Required\n";
else
cout<<"Optional\n";
}
}
}
}
}

void printAllInfo(string code, istringstream &iss)
{
if(code == "PB")
{
for(int i=0; i < classCounter; i++)
{
cout
if(classes[i]->course->deptCode==deptCode)
{
cout << isbn<<" " << title<<"\n";
}
}
}
else if(code == "PY")
{
int pmonth, pyear, checkMonth, checkYear;
int ch;
iss>>checkMonth>>ch>>checkYear;
for(int i=0; i < classCounter; i++){
istringstream isstreamer(books[i]->publicationDate);
isstreamer>>pmonth>>ch>>pyear;
if((pyear==checkYear && pmonth>checkMonth)||(pyear>checkYear))
{
//cout
}
}
}
}


Related Solutions

In C, write a program that initializes a 3D array (the exact size doesn't matter) that...
In C, write a program that initializes a 3D array (the exact size doesn't matter) that contain what ever arbitrary integers and print out the array including the elements and use different functions so that the main only contains variables and function calls.
Write a story you were told as child
Write a story you were told as child
The goal of this project is to practice (Write a C Program) with a function that...
The goal of this project is to practice (Write a C Program) with a function that one of its parameter is a function.The prototype of this function is: void func ( float (*f)(float*, int), float* a, int length); This means the function: func has three parameters: float (*f)(float*, int): This parameter itself is a function: f that has two parameters and returns a floating-point number. In the body of the function: func we call the function: f with its arguments...
Write a C++ die roller program. We need you to write a program that will roll...
Write a C++ die roller program. We need you to write a program that will roll dice for them, but not just six-sided dice. Your program needs to be able to take an input in for form nDx or ndx where the d is the letter d or D. n may or not be present. If it is, it represents the number of dice. If not, assume it is a 1. x may or may not be present. If it...
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for...
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for Bubble Sort b. Use a dynamic array of integers in a variable size of n. c. Display the following information: 1) Total counts of comparisons 2) Total counts of shifts / moves / swaps, whichever applies d. Write a main() function to test a best, and an average cases in terms of time efficiency i. Fill out the array with random numbers for an...
write a program in C Write a function that is passed an array of characters containing...
write a program in C Write a function that is passed an array of characters containing letter grades of A, B, C, D, and F, and returns the total number of occurrences of each letter grade. Your function should accept both lower and upper case grades, for example, both 'b' and 'B' should be bucketed into your running total for B grades. Any grade that is invalid should be bucketed as a grade of 'I' for Incomplete. You must use...
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
write C++ program using functions (separate function for each bottom) Write a program to find if...
write C++ program using functions (separate function for each bottom) Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. . the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function.
C++ Write a program that has two functions. The 1st function is the main function. The...
C++ Write a program that has two functions. The 1st function is the main function. The main function should prompt the user for three inputs: number 1, number 2, and an operator. The main function should call a 2nd function called calculate. The 2nd function should offer the choices of calculating addition, subtraction, multiplication, and division. Use a switch statement to evaluate the operator, then choose the appropriate calculation and return the result to the main function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT