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

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 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 story you were told as child
Write a story you were told as child
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.
1- Write it with C++ program §Write a function Rotate that rotates an array of size...
1- Write it with C++ program §Write a function Rotate that rotates an array of size n by d elements to the left §Use array as argument §In the main function, call the function Rotate and show the rotated array §Test your code For example: Input: [1 2 3 4 5 6 7], n = 7, d = 2 Output: [3 4 5 6 7 1 2] 2- Write it in C++ §Search Insert Position •Given a sorted array in...
In a c programming Write a program that converts upper case letters to lower case letters...
In a c programming Write a program that converts upper case letters to lower case letters or vice versa: Enter a sentence: What a GREAT movie is! Converted sentence: wHAT_A_great_MOVIE_IS_ Convert all non-alphabetical letters to ‘_’
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
Write a c program Write a function to swap two elements of an integer array. Call...
Write a c program Write a function to swap two elements of an integer array. Call the function to swap the first element, i[0] with last element i[n], second element i[1] with the last but one element i[n-1] and so on. Should handle arrays with even and odd number of elements. Call the swap function with the following arrays and print results in each case before and after swapping. i. int arr1[] = {0, 1, 2, 3, 30, 20, 10,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT