Advertisement
dinky_moop

courseRecords

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