Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //myApp.cpp
- #include <iostream>
- #include <string>
- #include <vector>
- #include <iomanip>
- #include "course.h"
- #include "utils.h"
- using namespace std;
- char menu();
- int main() {
- vector<courseType> list;
- readData(list);
- char ch = 'x';
- do {
- ch = menu();
- switch (ch) {
- case 'l':
- // function handler
- doDisplay(list);
- break;
- case 'v':
- doView(list);
- break;
- case 'a':
- doAdd(list);
- break;
- case 'e':
- doEdit(list);
- break;
- case 'd':
- doDelete(list);
- break;
- default:
- cout << "Please enter valid choice" << endl;
- }
- } while (ch != 'x');
- cout << "Exit the program" << endl;
- return 0; // exit the program successfully
- }
- /**
- * Display application menu
- */
- char menu() {
- cout << "Course Menu" << endl;
- cout << "=====================" << endl;
- cout << "l - Display list of courses" << endl;
- cout << "v - View course details" << endl;
- cout << "a - Add a course" << endl;
- cout << "e - Edit a course" << endl;
- cout << "d - Delete a course" << endl;
- cout << "x - Exit program" << endl << endl;
- cout << "Enter choice: ";
- char ch;
- cin >> ch;
- return ch;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //CourseImp.cpp
- #include <string>
- #include "course.h"
- #include <iostream>
- using namespace std;
- courseType::courseType() {
- term = "";
- year = 0.0;
- startDate = "";
- endDate = "";
- courseName = "";
- classID = "";
- section = "";
- meetingDays = "";
- location = "";
- meetingInfo = "";
- instructor = "";
- units = 0.0;
- }
- courseType::~courseType() {
- }
- /**
- * Function setTerm ...
- */
- void courseType::setTerm(string term) {
- this ->term = term;;
- }
- // accessor methods - get
- string courseType::getTerm() {
- return term;
- }
- void courseType::setYear(string temp) {
- this ->temp = temp;
- }
- // accessor methods - get
- string courseType::getYear() {
- return temp;
- }
- void courseType::setStart(string startDate) {
- this ->startDate = startDate;
- }
- // accessor methods - get
- string courseType::getStart() {
- return startDate;
- }
- void courseType::setEnd(string endDate) {
- this ->endDate = endDate;
- }
- // accessor methods - get
- string courseType::getEnd() {
- return endDate;
- }
- void courseType::setName(string courseName) {
- this ->courseName = courseName;
- }
- string courseType::getName() {
- return courseName;
- }
- // accessor methods - get
- void courseType::setID(string classID) {
- this ->classID = classID;
- }
- string courseType::getID() {
- return classID;
- }
- // accessor methods - get
- void courseType::setSection(string section) {
- this ->section = section;
- }
- string courseType::getSection() {
- return section;
- }
- // accessor methods - get
- void courseType::setDays(string meetingDays) {
- this ->meetingDays = meetingDays;;
- }
- string courseType::getDays() {
- return meetingDays;
- }
- // accessor methods - get
- void courseType::setLocation(string location) {
- this ->location = location;
- }
- string courseType::getLocation() {
- return location;
- }
- // accessor methods - get
- void courseType::setInfo(string meetingInfo) {
- this ->meetingInfo = meetingInfo;
- }
- string courseType::getInfo() {
- return meetingInfo;
- }
- void courseType::setInstructor(string instructor) {
- this ->instructor = instructor;
- }
- string courseType::getInstructor() {
- return instructor;
- }
- void courseType::setUnits(string tempU) {
- this ->tempU = tempU;
- }
- string courseType::getUnits() {
- return tempU;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //utils.cpp
- #include <iostream>
- #include <iomanip>
- #include "utils.h"
- #include "course.h"
- using namespace std;
- /**
- * Function display list of courses
- */
- void doDisplay(vector<courseType>& list) {
- cout << left << setw(10) << "Term" << setw(10) << "Year"
- << setw(15) << "Start Date" << setw(15) << "End Date"
- << setw(15) <<"Course Name" << setw(15) << "Class ID"
- << setw(12) << "Section" << setw(15) << "Meeting Days"
- << setw(15) << "Location" << setw(20) << "Meeting Info"
- << setw(15) << "Instructor" << "Units" << endl;
- cout << "----------------------------------------------------------------------------------";
- cout << "----------------------------------------------------------------------------------" << endl;
- for(int i = 0; i < list.size(); i++){
- cout << left << setw(10) << list[i].getTerm() << endl;
- }
- }
- void doView(vector<courseType>& list) {
- cout << "doView - todo" << endl;
- }
- void doAdd(vector<courseType>& list) {
- cout << "doAdd - todo" << endl;
- }
- void doEdit(vector<courseType>& list) {
- cout << "doEdit - todo" << endl;
- }
- void doDelete(vector<courseType>& list) {
- cout << "doDelete - todo" << endl;
- }
- void readData(vector<courseType>& list) {
- ifstream inFile;
- fstream fin;
- inFile.open(FILE_NAME);
- string line = "";
- while (getline(inFile, line)) {
- string term;
- float year;
- string startDate;
- string endDate;
- string courseName;
- string classID;
- string section;
- string meetingDays;
- string location;
- string meetingInfo;
- string instructor;
- float units;
- string temp;
- string tempU;
- while (getline(inFile, line)) {
- stringstream ss(line);
- getline(ss, term, ',');
- getline(ss, temp, ',');
- year = atoi(temp.c_str());
- getline(ss, startDate, ',');
- getline(ss, endDate, ',');
- getline(ss, courseName, ',');
- getline(ss, classID, ',');
- getline(ss, section, ',');
- getline(ss, meetingDays, ',');
- getline(ss, location, ',');
- getline(ss, meetingInfo, ',');
- getline(ss, instructor, ',');
- getline(ss,tempU,',');
- units = atoi(tempU.c_str());
- courseType c;
- c.setTerm(term);
- list.push_back(c);
- courseType d;
- d.setYear(temp);
- list.push_back(d);
- courseType e;
- e.setStart(startDate);
- list.push_back(e);
- courseType f;
- f.setEnd(endDate);
- list.push_back(f);
- courseType g;
- g.setName(courseName);
- list.push_back(g);
- courseType h;
- h.setID(classID);
- list.push_back(h);
- courseType i;
- i.setSection(section);
- list.push_back(i);
- courseType j;
- j.setDays(meetingDays);
- list.push_back(j);
- courseType k;
- k.setLocation(location);
- list.push_back(k);
- courseType l;
- l.setInfo(meetingInfo);
- list.push_back(l);
- courseType m;
- m.setInstructor(instructor);
- list.push_back(m);
- courseType n;
- n.setUnits(tempU);
- list.push_back(n);
- }
- inFile.close();
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //course.h
- #pragma once
- #include <string>
- #include <sstream>
- using namespace std;
- class courseType {
- public:
- // mutator methods - set
- void setTerm(string term);
- void setYear(string temp);
- void setStart(string startDate);
- void setEnd(string endDate);
- void setName(string courseName);
- void setID(string classID);
- void setSection(string section);
- void setDays(string meetingDays);
- void setLocation(string location);
- void setInstructor(string instructor);
- void setInfo(string meetingInfo);
- void setUnits(string tempU);
- // ...
- // accessor methods - get
- string getTerm();
- string getYear();
- string getStart();
- string getEnd();
- string getName();
- string getID();
- string getSection();
- string getDays();
- string getLocation();
- string getInstructor();
- string getInfo();
- string getUnits();
- // ...
- // Other member methods
- // ...
- courseType();
- ~courseType();
- protected:
- // tbd
- private:
- // data structures
- string term;
- float year;
- string startDate;
- string endDate;
- string courseName;
- string classID;
- string section;
- string meetingDays;
- string location;
- string meetingInfo;
- string instructor;
- float units;
- string temp;
- string tempU;
- };
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //utils.h
- #pragma once
- #include <string>
- #include <vector>
- #include <fstream>
- #include <sstream>
- #include "course.h"
- using namespace std;
- const string FILE_NAME = "courses.csv";
- // Prototype functions...
- void doDisplay(vector<courseType>& list);
- void doView(vector<courseType>& list);
- void doAdd(vector<courseType>& list);
- void doEdit(vector<courseType>& list);
- void doDelete(vector<courseType>& list);
- void readData(vector<courseType>& list);
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////courses.csv
- Spring,2022,1/24/2022,5/20/2022,Discrete Structures,CS-113-02,085689,T TH,On-Campus,Newark,Pham,3
- Spring,2022,1/24/2022,5/20/2022,Programming W/ Data Structures,CS-124-02,084371,M W,On-Campus,Zoom,Pham,3
- Spring,2022,1/24/2022,5/20/2022,Programming W/ Data Structures,CS-124-03,085698,T TH,Online,Newark,Pham,3
- Spring,2022,1/24/2022,5/20/2022,JavaScript for Web Development,CS-175-01,084377,M,Online,Zoom,J. Pham,4
- Spring,2022,1/24/2022,5/20/2022,Beginner Java,CS-125-05,089434,TH,Online,Zoom,Gao,3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement