Question

NEED HELP WITH MY C++ ASSIGNMENT, IT NEEDS TO BE SOLVED USING LISTS #include <iostream> #include...

NEED HELP WITH MY C++ ASSIGNMENT, IT NEEDS TO BE SOLVED USING LISTS
#include <iostream>
#include <list>
#include <map>
#include <string>
using namespace std;

class course {
public:
        string name;
        int section;
        int credits;
        course() {}
        course(string n, int s, int c) { name = n; section = s; credits = c; }
        //Add additional needed member functions and implement them.
        //You also need to implement some needed functions for overloading operator<< .
};
//Implement the following functions

void add_student(map<int, map<int, list<course*>* > >& DB, int id);
void remove_student(map<int, map<int, list<course*>* > >& DB, int id);
void add_course(map<int, map<int, list<course*>* > >& DB, int semester, int id, course c); //20171 Spring semester of 2017; 20172: Fall semester of 2017

void drop_course(map<int, map<int, list<course*>* > >& DB, int semester, int id, course c);
void print_student_semester_courses(map<int, map<int, list<course*>* > >& DB, int semester, int id);
void print_student_all_courses(map<int, map<int, list<course*>* > >& DB, int id);
void print_DB(map<int, map<int, list<course*>* > >& DB);

//For the print funcitons, you need to add more fucntions to overload operator<<.
//for example print_DB is simply cout << DB;
//Courses in a semeste are sorted alphabetically.

int main() {
        //Do not change code for main function
        map<int, map<int, list <course*>*> > DB;
        add_student(DB, 11111);
        course C1("CIS554", 1, 3), C2("CSE674", 1, 3), C3("MAT296", 8, 4), C4("WRT205", 5, 3);

        add_course(DB, 20171, 11111, C1);
        add_course(DB, 20171, 11111, C4);
        add_course(DB, 20171, 11111, C3);
        add_course(DB, 20171, 11111, C2);
        print_student_semester_courses(DB, 20171, 11111);

        drop_course(DB, 20171, 11111, C1);
        print_student_semester_courses(DB, 20171, 11111);

        add_course(DB, 20172, 11111, C2);
        add_course(DB, 20172, 11111, C4);
        add_course(DB, 20172, 11111, C3);
        add_course(DB, 20172, 11111, C1);
        print_student_all_courses(DB, 11111);

        add_student(DB, 11112);
        add_course(DB, 20171, 11112, C2);
        add_course(DB, 20171, 11112, C4);
        add_course(DB, 20171, 11112, C3);
        add_course(DB, 20171, 11112, C1);
        print_student_semester_courses(DB, 20171, 11112);

        add_course(DB, 20172, 11112, C2);
        add_course(DB, 20172, 11112, C4);
        add_course(DB, 20172, 11112, C3);
        add_course(DB, 20172, 11112, C1);
        print_student_semester_courses(DB, 20172, 11112);
        print_student_all_courses(DB, 11112);
        print_DB(DB);
        remove_student(DB, 11111);
        print_DB(DB);
        getchar();
        getchar();
        return 0;
}

void add_student(map<int, map<int, list<course*>* >>& DB, int id) {


}

void remove_student(map<int, map<int, list<course*>* >>& DB, int id) {

}


void add_course(map<int, map<int, list<course*>* >>& DB, int semester, int id, course c) {

}

void drop_course(map<int, map<int, list<course*>* >>& DB, int semester, int id, course c) {

}

void print_student_semester_courses(map<int, map<int, list<course*>* >>& DB, int semester, int id) {

}
void print_student_all_courses(map<int, map<int, list<course*>* >>& DB, int id) {

}

void print_DB(map<int, map<int, list<course*>* >>& DB) {

}
//Some additional functions for overloading operator<<


/*
//Your output needs to keep the identical format
//Sample Screenshot
student id = 11111
semester = 20171
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3

student id = 11111
semester = 20171
CSE674 1 3  MAT296 8 4  WRT205 5 3

student id = 11111
semester = 20171
CSE674 1 3  MAT296 8 4  WRT205 5 3
semester = 20172
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3

student id = 11112
semester = 20171
CIS554 1 3  CSE674 1 3   MAT296 8 4  WRT205 5 3

student id = 11112
semester = 20172
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3

student id = 11112
semester = 20171
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3
semester = 20172
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3

student id = 11111
semester = 20171
CSE674 1 3  MAT296 8 4  WRT205 5 3
semester = 20172
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3
student id = 11112
semester = 20171
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3
semester = 20172
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3

student id = 11112
semester = 20171
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3
semester = 20172
CIS554 1 3  CSE674 1 3  MAT296 8 4  WRT205 5 3
*/
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:
#include <iostream>
#include <list>
#include <map>
#include <string>
using namespace std;

class course {
public:
   string name;
   int section;
   int credits;
   course() {}
   course(string n, int s, int c) { name = n; section = s; credits = c; }
   //Add additional needed member functions and implement them.
   //You also need to implement some needed functions for overloading operator<< .
   friend ostream& operator << (ostream& out, const course& c);
};
//Implement the following functions

void add_student(map<int, map<int, list<course*>* > >& DB, int id);
void remove_student(map<int, map<int, list<course*>* > >& DB, int id);
void add_course(map<int, map<int, list<course*>* > >& DB, int semester, int id, course& c); //20171 Spring semester of 2017; 20172: Fall semester of 2017

void drop_course(map<int, map<int, list<course*>* > >& DB, int semester, int id, course& c);
void print_student_semester_courses(map<int, map<int, list<course*>* > >& DB, int semester, int id);
void print_student_all_courses(map<int, map<int, list<course*>* > >& DB, int id);
void print_DB(map<int, map<int, list<course*>* > >& DB);

//For the print funcitons, you need to add more fucntions to overload operator<<.
//for example print_DB is simply cout << DB;
//Courses in a semeste are sorted alphabetically.

int main() {
   //Do not change code for main function
   map<int, map<int, list <course*>*> > DB;
   add_student(DB, 11111);
   course C1("CIS554", 1, 3), C2("CSE674", 1, 3), C3("MAT296", 8, 4), C4("WRT205", 5, 3);

   add_course(DB, 20171, 11111, C1);
   add_course(DB, 20171, 11111, C4);
   add_course(DB, 20171, 11111, C3);
   add_course(DB, 20171, 11111, C2);
   print_student_semester_courses(DB, 20171, 11111);

   drop_course(DB, 20171, 11111, C1);
   print_student_semester_courses(DB, 20171, 11111);

   add_course(DB, 20172, 11111, C2);
   add_course(DB, 20172, 11111, C4);
   add_course(DB, 20172, 11111, C3);
   add_course(DB, 20172, 11111, C1);
   print_student_all_courses(DB, 11111);

   add_student(DB, 11112);
   add_course(DB, 20171, 11112, C2);
   add_course(DB, 20171, 11112, C4);
   add_course(DB, 20171, 11112, C3);
   add_course(DB, 20171, 11112, C1);
   print_student_semester_courses(DB, 20171, 11112);

   add_course(DB, 20172, 11112, C2);
   add_course(DB, 20172, 11112, C4);
   add_course(DB, 20172, 11112, C3);
   add_course(DB, 20172, 11112, C1);
   print_student_semester_courses(DB, 20172, 11112);
   print_student_all_courses(DB, 11112);
   print_DB(DB);
   remove_student(DB, 11111);
   print_DB(DB);
   getchar();
   getchar();
   return 0;
}

void add_student(map<int, map<int, list<course*>* >>& DB, int id) {

   map<int, list<course*>*> m;
   DB[id] = m;
}

void remove_student(map<int, map<int, list<course*>* >>& DB, int id) {
   DB.erase(id);
}


void add_course(map<int, map<int, list<course*>* >>& DB, int semester, int id, course& c) {
   if(nullptr == DB[id][semester])
   {
       list<course*>* l = new list<course*>();
       DB[id][semester] = l;
   }
   DB[id][semester]->push_back(&c);
}

void drop_course(map<int, map<int, list<course*>* >>& DB, int semester, int id, course& c) {
   DB[id][semester]->remove(&c);
}

void print_student_semester_courses(map<int, map<int, list<course*>* >>& DB, int semester, int id) {
   cout << "\nStudent Id : " << id;
   cout << "\nSemester : " << semester<<endl;

   for(course* c : *DB[id][semester])
   {
       cout << *c <<" ";
   }

   cout << endl ;

}
void print_student_all_courses(map<int, map<int, list<course*>* >>& DB, int id) {
   cout << "\nStudent Id : " << id;
   for (auto pair : DB[id])
   {
       cout << "\nSemester : " << pair.first << endl;
       for (course* c : *DB[id][pair.first])
       {
           cout << *c<<" ";
       }
   }
   cout << endl;
}

void print_DB(map<int, map<int, list<course*>* >>& DB) {
   for (auto stu : DB)
   {
       cout << "\nStudent Id : " << stu.first;
       for (auto pair : DB[stu.first])
       {
           cout << "\nSemester : " << pair.first<<endl;
           for (course* c : *DB[stu.first][pair.first])
           {
               cout << *c<<" ";
           }
       }
   }
   cout << endl ;
}
//Some additional functions for overloading operator<<
ostream& operator<<(ostream& out, const course& c)
{
   out << c.name << " " << c.section << " " << c.credits;
   return out;
}

OUTPUT:

Student Id : 11111 Semester : 20171 CIS554 1 3 WRT205 5 3 MAT296 84 CSE674 1 3 Student Id : 11111 Semester : 20171 WRT205 5 3

Add a comment
Answer #2
/ main program

#include <iostream>
using namespace std;
#include <cstring>

/*
   program:         studentID_PRG355X.221.LT1.cpp
   student:         student name here...
   student number:  123456789
   date:            april 12, 2022
   purpose:         solution to PRG355X Lab Test #2
*/

/*
   Your class declaration and member functions MUST be placed here...
*/

int main( ) {
   struct fish array[10] = { {"shark", 'S', 3187287.98}, {"eel", 'S', 7299.35},     {"trout", 'F', 5126.42},
                             {"bass", 'F', 1892.33},     {"sunfish", 'F', 192.25},  {"tuna", 'S', 87553.78},    {"catfish", 'F', 427.76},
                             {"muskee", 'F', 897.22},    {"striper", 'S', 1235.71}, {"guppy", 'F', 82.11} };

   Aquarium tank1(8);

   int i, rv;

   for(i=0; i<10; i++) {
      rv = tank.add(array[i]);
      if(rv)
         cout << "added fish " << i + 1 << endl;
      else
         cout << "could not add fish..." << endl;
   }

   tank1.feed( ); // increases all saltwater fish by 500 grams and all freshwater fish by 15 grams
   tank1.feed(1); // parameter used to differentiate between feed( ) function calls only
                  // this function results in the shark "eating" the sunfish!
   cout << "==========" << endl;
   cout << tank1; // displays all fish in the tank

   return 0;
}

/*
would display:
added fish 1
added fish 2
added fish 3
added fish 4
added fish 5
added fish 6
added fish 7
added fish 8
could not add fish...
could not add fish...
==========
shark S 3187995.23
eel S 7799.35
trout F 5141.42
bass F 1907.33
unclassified U 0.00
tuna S 88053.78
catfish F 442.76
muskee F 913.22
*/


source: c++
answered by: anonymous
Add a comment
Know the answer?
Add Answer to:
NEED HELP WITH MY C++ ASSIGNMENT, IT NEEDS TO BE SOLVED USING LISTS #include <iostream> #include...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello I need help fixing my C++ code. I need to display in the console the...

    Hello I need help fixing my C++ code. I need to display in the console the information saved in the file as well have the content saved in the file output in a fixed position like the screenshot. Thanks. CODE #include<iostream> #include<fstream> #include<iomanip> using namespace std; //main function int main() {    //variable to store student id    int id;       //variables to store old gpa(ogpa), old course credits(occ), new course credits(ncc), current gpa(cur_gpa), cumulative gpa(cum_gpa)    float ogpa,...

  • Using C programming (Microsoft Visual Studio) This is the code I have #include "pch.h" #include <iostream>...

    Using C programming (Microsoft Visual Studio) This is the code I have #include "pch.h" #include <iostream> #include <string.h> #include <stdlib.h> #include <stdio.h> #include<dos.h> #include <iostream> int id_arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; int pid_arr[] = { 0, 0, 0, 1, 13, 1, 2, 2, 5, 5, 5, 10, 4 }; char title_arr[][100] = { "Books & Audibles", "Electronics", "Food", "Books", "Science & Mathematics books", "Fictions", "Phones", "Appliances", "Astronomy", "Physics",...

  • (1) Declaration and implementation of complex class, overloading operator +, -, != , /, --(prefix), --(postfix)...

    (1) Declaration and implementation of complex class, overloading operator +, -, != , /, --(prefix), --(postfix) as friend functions.         (2)The program should be in Separating Class Specification, Implementation(complex.h,complex.cpp), and Client Code(Task2.cpp).             (3) Run the program and capture screenshots of output. Declaration and implementation of complex class, overloading operator +, -, != , /=, --(prefix), --(postfix) as friend function */ #include "Complex.h" #include <iostream> using namespace std; int main(){       Complex c1(5, 4), c2(2, 10), c3;       cout <<...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType va...

    C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType value;    Node *next; }; class LinkedList { private:    Node *head;    // You may add whatever private data members or private member functions you want to this class.    void printReverseRecursiveHelper(Node *temp) const; public:    // default constructor    LinkedList() : head(nullptr) { }    // copy constructor    LinkedList(const LinkedList& rhs);    // Destroys all the dynamically allocated memory    //...

  • Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car...

    Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car class //Defined enum here enum Kind{business,maintenance,other,box,tank,flat,otherFreight,chair,seater,otherPassenger}; //Defined array of strings string KIND_ARRAY[]={"business","maintenance","other,box","tank,flat","otherFreight","chair","seater","otherPassenger"}; class Car { private: string reportingMark; int carNumber; Kind kind; //changed to Kind bool loaded; string destination; public: //Defined setKind function Kind setKind(string knd) { for(int i=0;i<8;i++) //repeat upto 8 kinds { if(knd.compare(KIND_ARRAY[i])==0) //if matched in Array kind=(Kind)i; //setup that kind } return kind; } //Default constructor Car() { } //Parameterized constructor...

  • C++ #include <iostream> using namespace std; bool checkinventoryid(int id) {    return id > 0; }...

    C++ #include <iostream> using namespace std; bool checkinventoryid(int id) {    return id > 0; } bool checkinventoryprice(float price) {    return price > 0; } void endProgram() {    system("pause");    exit(0); } void errorID(string str) {    cout << "Invalid Id!!! " << str << " should be greater than 0" << endl; } void errorPrice(string str) {    cout << "Invalid Price!!!" << str << " should be greater than 0" << endl; } int inputId() {...

  • Place the following tables in BCNF / 4NF 1) c3 ? c4 c2 ? c7 c1...

    Place the following tables in BCNF / 4NF 1) c3 ? c4 c2 ? c7 c1 ? ? c5 (c1,c2) ? c6 2) Zoo database Animal id uniquely identifies each individual animal at the zoo. If you know an animal id, you know the animal type, feeding time, location, animal food, cleaning time, medicines, and vet. Cleaning time and feeding times are done by location. Each type of animal has its own assigned vet and assigned food. Medicines, of course,...

  • Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...

    Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...

  • I need help with this code: #include <iostream> #include <cstdlib> #include <string> using namespace std; void...

    I need help with this code: #include <iostream> #include <cstdlib> #include <string> using namespace std; void dump(int ar[], int size) { cout << "\nDUMP [ "; for (int i=0; i<=size; i++) { cout << ar[i] << " "; } cout << "]\n\n"; } void quicksort(int ar[], int start, int end) { cout << "TOP OF SORT ===========================" << endl; dump(ar, start, end); int pivot = ar[end]; int left = start; int right = end - 1; int tmp; cout <<...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT