Advertisement
dinky_moop

Code

Mar 4th, 2022
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.13 KB | None | 0 0
  1. //myApp.cpp
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <iomanip>
  6. #include "course.h"
  7. #include "utils.h"
  8.  
  9. using namespace std;
  10.  
  11. char menu();
  12.  
  13. int main() {
  14.  
  15.     vector<courseType> list;
  16.     readData(list);
  17.  
  18.     char ch = 'x';
  19.     do {
  20.         ch = menu();
  21.         switch (ch) {
  22.         case 'l':
  23.             // function handler
  24.             doDisplay(list);
  25.             break;
  26.         case 'v':
  27.             doView(list);
  28.             break;
  29.         case 'a':
  30.             doAdd(list);
  31.             break;
  32.         case 'e':
  33.             doEdit(list);
  34.             break;
  35.         case 'd':
  36.             doDelete(list);
  37.             break;
  38.         default:
  39.             cout << "Please enter valid choice" << endl;
  40.         }
  41.     } while (ch != 'x');
  42.  
  43.     cout << "Exit the program" << endl;
  44.  
  45.     return 0; // exit the program successfully
  46. }
  47.  
  48. /**
  49. * Display application menu
  50. */
  51. char menu() {
  52.  
  53.     cout << "Course Menu" << endl;
  54.     cout << "=====================" << endl;
  55.     cout << "l - Display list of courses" << endl;
  56.     cout << "v - View course details" << endl;
  57.     cout << "a - Add a course" << endl;
  58.     cout << "e - Edit a course" << endl;
  59.     cout << "d - Delete a course" << endl;
  60.     cout << "x - Exit program" << endl << endl;
  61.     cout << "Enter choice: ";
  62.     char ch;
  63.     cin >> ch;
  64.     return ch;
  65. }
  66.  
  67. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  68. //CourseImp.cpp
  69. #include <string>
  70. #include "course.h"
  71. #include <iostream>
  72.  
  73. using namespace std;
  74.  
  75. courseType::courseType() {
  76.     term = "";
  77.     year = 0.0;
  78.     startDate = "";
  79.     endDate = "";
  80.     courseName = "";
  81.     classID = "";
  82.     section = "";
  83.     meetingDays = "";
  84.     location = "";
  85.     meetingInfo = "";
  86.     instructor = "";
  87.     units = 0.0;
  88. }
  89. courseType::~courseType() {
  90. }
  91. /**
  92.  * Function setTerm ...
  93.  */
  94. void courseType::setTerm(string term) {
  95.     this ->term = term;;
  96. }
  97.  
  98. // accessor methods - get
  99. string courseType::getTerm() {
  100.     return term;
  101. }
  102. void courseType::setYear(string temp) {
  103.     this ->temp = temp;
  104. }
  105.  
  106. // accessor methods - get
  107. string courseType::getYear() {
  108.     return temp;
  109. }
  110. void courseType::setStart(string startDate) {
  111.     this ->startDate = startDate;
  112. }
  113.  
  114. // accessor methods - get
  115. string courseType::getStart() {
  116.     return startDate;
  117. }
  118. void courseType::setEnd(string endDate) {
  119.     this ->endDate = endDate;
  120. }
  121.  
  122. // accessor methods - get
  123. string courseType::getEnd() {
  124.     return endDate;
  125. }
  126. void courseType::setName(string courseName) {
  127.     this ->courseName = courseName;
  128. }
  129. string courseType::getName() {
  130.     return courseName;
  131. }
  132.  
  133. // accessor methods - get
  134. void courseType::setID(string classID) {
  135.     this ->classID = classID;
  136. }
  137. string courseType::getID() {
  138.     return classID;
  139. }
  140.  
  141. // accessor methods - get
  142. void courseType::setSection(string section) {
  143.     this ->section = section;
  144. }
  145. string courseType::getSection() {
  146.     return section;
  147. }
  148.  
  149. // accessor methods - get
  150. void courseType::setDays(string meetingDays) {
  151.     this ->meetingDays = meetingDays;;
  152. }
  153. string courseType::getDays() {
  154.     return meetingDays;
  155. }
  156.  
  157. // accessor methods - get
  158. void courseType::setLocation(string location) {
  159.     this ->location = location;
  160. }
  161.  
  162. string courseType::getLocation() {
  163.     return location;
  164. }
  165. // accessor methods - get
  166. void courseType::setInfo(string meetingInfo) {
  167.     this ->meetingInfo = meetingInfo;
  168. }
  169.  
  170. string courseType::getInfo() {
  171.     return meetingInfo;
  172. }
  173.  
  174. void courseType::setInstructor(string instructor) {
  175.     this ->instructor = instructor;
  176. }
  177.  
  178. string courseType::getInstructor() {
  179.     return instructor;
  180. }
  181. void courseType::setUnits(string tempU) {
  182.     this ->tempU = tempU;
  183. }
  184. string courseType::getUnits() {
  185.     return tempU;
  186. }
  187.  
  188. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  189. //utils.cpp
  190. #include <iostream>
  191. #include <iomanip>
  192. #include "utils.h"
  193. #include "course.h"
  194.  
  195. using namespace std;
  196.  
  197. /**
  198.  * Function display list of courses
  199.  */
  200. void doDisplay(vector<courseType>& list) {
  201.     cout << left << setw(10) << "Term" << setw(10) << "Year"
  202.     << setw(15) << "Start Date" << setw(15) << "End Date"
  203.     << setw(15) <<"Course Name" << setw(15) << "Class ID"
  204.     << setw(12) << "Section" << setw(15) << "Meeting Days"
  205.     << setw(15) << "Location" << setw(20) << "Meeting Info"
  206.     << setw(15) << "Instructor" << "Units" << endl;
  207.     cout << "----------------------------------------------------------------------------------";
  208.     cout << "----------------------------------------------------------------------------------" << endl;
  209.    
  210.     for(int i = 0; i < list.size(); i++){
  211.          
  212.         cout << left << setw(10) << list[i].getTerm() << endl;
  213.     }
  214. }
  215. void doView(vector<courseType>& list) {
  216.     cout << "doView - todo" << endl;
  217. }
  218.  
  219. void doAdd(vector<courseType>& list) {
  220.     cout << "doAdd - todo" << endl;
  221. }
  222.  
  223. void doEdit(vector<courseType>& list) {
  224.     cout << "doEdit - todo" << endl;
  225. }
  226.  
  227. void doDelete(vector<courseType>& list) {
  228.     cout << "doDelete - todo" << endl;
  229. }
  230.  
  231. void readData(vector<courseType>& list) {
  232.  
  233.     ifstream inFile;
  234.     fstream fin;
  235.     inFile.open(FILE_NAME);
  236.     string line = "";
  237.     while (getline(inFile, line)) {
  238.        
  239.         string term;
  240.         float year;
  241.         string startDate;
  242.         string endDate;
  243.         string courseName;
  244.         string classID;
  245.         string section;
  246.         string meetingDays;
  247.         string location;
  248.         string meetingInfo;
  249.         string instructor;
  250.         float units;
  251.         string temp;
  252.         string tempU;
  253.        
  254.     while (getline(inFile, line)) {
  255.         stringstream ss(line);
  256.         getline(ss, term, ',');
  257.         getline(ss, temp, ',');
  258.         year = atoi(temp.c_str());
  259.         getline(ss, startDate, ',');
  260.         getline(ss, endDate, ',');
  261.         getline(ss, courseName, ',');
  262.         getline(ss, classID, ',');
  263.         getline(ss, section, ',');
  264.         getline(ss, meetingDays, ',');
  265.         getline(ss, location, ',');
  266.         getline(ss, meetingInfo, ',');
  267.         getline(ss, instructor, ',');
  268.         getline(ss,tempU,',');
  269.         units = atoi(tempU.c_str());
  270.      
  271.        
  272.         courseType c;
  273.         c.setTerm(term);
  274.         list.push_back(c);
  275.        
  276.         courseType d;
  277.         d.setYear(temp);
  278.         list.push_back(d);
  279.        
  280.        
  281.         courseType e;
  282.         e.setStart(startDate);
  283.         list.push_back(e);
  284.                
  285.         courseType f;
  286.         f.setEnd(endDate);
  287.         list.push_back(f);
  288.        
  289.         courseType g;
  290.         g.setName(courseName);
  291.         list.push_back(g);
  292.                
  293.         courseType h;
  294.         h.setID(classID);
  295.         list.push_back(h);
  296.                
  297.         courseType i;
  298.         i.setSection(section);
  299.         list.push_back(i);
  300.                
  301.         courseType j;
  302.         j.setDays(meetingDays);
  303.         list.push_back(j);
  304.                
  305.         courseType k;
  306.         k.setLocation(location);
  307.         list.push_back(k);
  308.                
  309.         courseType l;
  310.         l.setInfo(meetingInfo);
  311.         list.push_back(l);
  312.                
  313.         courseType m;
  314.         m.setInstructor(instructor);
  315.         list.push_back(m);
  316.                
  317.         courseType n;
  318.         n.setUnits(tempU);
  319.         list.push_back(n);
  320.        
  321.     }
  322.        
  323.     inFile.close();
  324.  
  325.     }
  326. }
  327.  
  328. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  329. //course.h
  330. #pragma once
  331. #include <string>
  332. #include <sstream>
  333.  
  334. using namespace std;
  335.  
  336. class courseType {
  337. public:
  338.     // mutator methods - set
  339.     void setTerm(string term);
  340.     void setYear(string temp);
  341.     void setStart(string startDate);
  342.     void setEnd(string endDate);
  343.     void setName(string courseName);
  344.     void setID(string classID);
  345.     void setSection(string section);
  346.     void setDays(string meetingDays);
  347.     void setLocation(string location);
  348.     void setInstructor(string instructor);
  349.     void setInfo(string meetingInfo);
  350.     void setUnits(string tempU);
  351.     // ...
  352.  
  353.     // accessor methods - get
  354.     string getTerm();
  355.     string getYear();
  356.     string getStart();
  357.     string getEnd();
  358.     string getName();
  359.     string getID();
  360.     string getSection();
  361.     string getDays();
  362.     string getLocation();
  363.     string getInstructor();
  364.     string getInfo();
  365.     string getUnits();
  366.    
  367.     // ...
  368.  
  369.     // Other member methods
  370.     // ...
  371.  
  372.     courseType();
  373.     ~courseType();
  374.  
  375. protected:
  376.     // tbd
  377.  
  378. private:
  379.     // data structures
  380.     string term;
  381.     float year;
  382.     string startDate;
  383.     string endDate;
  384.     string courseName;
  385.     string classID;
  386.     string section;
  387.     string meetingDays;
  388.     string location;
  389.     string meetingInfo;
  390.     string instructor;
  391.     float units;
  392.     string temp;
  393.     string tempU;
  394. };
  395.  
  396. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  397. //utils.h
  398. #pragma once
  399. #include <string>
  400. #include <vector>
  401. #include <fstream>
  402. #include <sstream>
  403. #include "course.h"
  404.  
  405. using namespace std;
  406.  
  407. const string FILE_NAME = "courses.csv";
  408.  
  409. // Prototype functions...
  410. void doDisplay(vector<courseType>& list);
  411. void doView(vector<courseType>& list);
  412. void doAdd(vector<courseType>& list);
  413. void doEdit(vector<courseType>& list);
  414. void doDelete(vector<courseType>& list);
  415. void readData(vector<courseType>& list);
  416.  
  417. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////courses.csv
  418. Spring,2022,1/24/2022,5/20/2022,Discrete Structures,CS-113-02,085689,T TH,On-Campus,Newark,Pham,3
  419. Spring,2022,1/24/2022,5/20/2022,Programming W/ Data Structures,CS-124-02,084371,M W,On-Campus,Zoom,Pham,3
  420. Spring,2022,1/24/2022,5/20/2022,Programming W/ Data Structures,CS-124-03,085698,T TH,Online,Newark,Pham,3
  421. Spring,2022,1/24/2022,5/20/2022,JavaScript for Web Development,CS-175-01,084377,M,Online,Zoom,J. Pham,4
  422. 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