Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.01 KB | None | 0 0
  1. #include "cc.h"
  2.  
  3. int main(int argc, char** argv) {
  4. bool again=1;
  5. Course c;
  6. ifstream catalogIn("catalog.dat");
  7. ofstream catalogOut("catalog.dat");
  8. Course courseCatalog[256];
  9.  
  10. loadInCourses(catalogIn, courseCatalog);
  11.  
  12. courseCatalog[getNumCourses(courseCatalog)+1]=addCourse();
  13.  
  14. loadOutCourses(catalogOut, courseCatalog);
  15.  
  16. return 0;
  17. }
  18.  
  19. #include "cc.h"
  20.  
  21. int displayMainMenu(){
  22. int choice;
  23. cout<<endl<<"**********MAIN MENU**********"<<endl;
  24. cout<<"1. Print List Schedule"<<endl;
  25. cout<<"2. Print Weekly Schedule"<<endl;
  26. cout<<"3. Get Course"<<endl;
  27. cout<<"4. Advanced Options"<<endl;
  28. cout<<"0 to Quit"<<endl;
  29. cout<<"*****************************"<<endl<<endl;
  30. cout<<"Menu Choice: ";
  31. cin>>choice;
  32. return choice;
  33. }
  34. int displayAdvMenu(){
  35. int choice;
  36. cout<<endl<<"**********ADV MENU**********"<<endl;
  37. cout<<"1. Add Course to Catalog"<<endl;
  38. cout<<"2. Remove Duplicates"<<endl;
  39. cout<<"0 to go Back"<<endl;
  40. cout<<"****************************"<<endl<<endl;
  41. cout<<"Menu Choice: ";
  42. cin>>choice;
  43. return choice;
  44. }
  45.  
  46. Course addCourse(){
  47. Course course;
  48.  
  49. cout<<"nCourse name:tt";
  50. cin.ignore();
  51. cin.getline(course.name, CNAMESIZE);
  52.  
  53. cout<<"Course ID:tt";
  54. cin.getline(course.id, CIDSIZE);
  55.  
  56. cout<<"Number of credits:t";
  57. cin>>course.credits;
  58.  
  59. return course;
  60. }
  61.  
  62. void loadInCourses(ifstream & ifs, Course courseCatalog[]){
  63. int i=0;
  64. while(ifs>>courseCatalog[i].credits){
  65. ifs.getline(courseCatalog[i].name, CNAMESIZE, ',');
  66. ifs.getline(courseCatalog[i].id, CIDSIZE, ',');
  67. ifs.getline(courseCatalog[i].professor, CPROFSIZE, ',');
  68. ifs.getline(courseCatalog[i].semester, CSEMSIZE, ',');
  69. ifs.get(courseCatalog[i].grade);
  70. i++;
  71. }
  72. return;
  73. }
  74.  
  75. void loadOutCourses(ofstream & ofs, Course courseCatalog[]){
  76. for(int i=0; i<=getNumCourses(courseCatalog); i++){
  77. ofs<<courseCatalog[i].credits<<
  78. courseCatalog[i].name<<","<<
  79. courseCatalog[i].id<<","<<
  80. courseCatalog[i].professor<<","<<
  81. courseCatalog[i].semester<<","<<
  82. courseCatalog[i].grade<<endl;
  83. }
  84. }
  85.  
  86. Course findCourse(ifstream & ifs){
  87. char attribute;
  88. string needle;
  89. int credits;
  90. int name;
  91. int id;
  92. bool again=1;
  93. int numLines = getNumLines(ifs);
  94.  
  95. cout<<"Search by (N)ame or (I)d? ";
  96. cin>>attribute;
  97. while(again){
  98. switch(attribute){
  99. case 'N': case 'n':
  100. cout<<"Enter name of course: ";
  101. cin>>name;
  102. for(int i=0; i<numLines; i++){
  103.  
  104. }
  105. break;
  106. case 'I': case 'i':
  107. cout<<"Enter course ID: ";
  108. cin>>id;
  109. break;
  110. default:
  111. cout<<"Invalid Attribute. Try Again."<<endl;
  112. }
  113. }
  114. }
  115.  
  116. int getNumCourses(Course courseCatalog[]){
  117. int numcourses=0;
  118. for(int i=0;courseCatalog[i].credits!=0;i++){
  119. numcourses++;
  120. }
  121. return numcourses;;
  122. }
  123.  
  124. int getNumLines(ifstream & ifs){
  125. char line[1];
  126. int count=0;
  127.  
  128. while(ifs.getline(line, 1)){
  129. count++;
  130. }
  131.  
  132. ifs.close();
  133. return count;
  134. }
  135.  
  136. ostream& operator<<(ostream& os, const Course c){
  137. os<<endl<<c.name<<endl<<c.id<<endl<<c.credits<<" cr hrs"<<endl;
  138. return os;
  139. }
  140.  
  141. #ifndef CC_H
  142. #define CC_H
  143.  
  144. #include <iostream>
  145. #include <fstream>
  146. #include <cstdlib>
  147. #include <cstring>
  148. using namespace std;
  149.  
  150. const int PREREQ_SIZE = 15;
  151. const int POSTREQ_SIZE = 15;
  152. const int CNAMESIZE=40;
  153. const int CIDSIZE=15;
  154. const int CPROFSIZE=40;
  155. const int CSEMSIZE=15;
  156.  
  157. struct Course{
  158. char name[CNAMESIZE];
  159. char id[CIDSIZE];
  160. int credits;
  161. char professor[CPROFSIZE];
  162. char semester[CSEMSIZE];
  163. char grade;
  164. float timeStart;
  165. float timeStop;
  166. friend ostream& operator<<(ostream& os, const Course c);
  167. };
  168.  
  169. Course addCourse();
  170. int displayMainMenu();
  171. int displayAdvMenu();
  172. void printString(Course c);
  173. void loadInCourses(ifstream & ifs, Course courseCatalog);
  174. void loadOutCourses(ofstream & ofs, Course courseCatalog);
  175. Course findCourse(ifstream & ifs);
  176. int getNumCourses(Course courseCatalog[]);
  177. int getNumLines(ifstream & ifs);
  178.  
  179. #endif
  180.  
  181. #include "cc.h"
  182.  
  183. int main(int argc, char** argv) {
  184. bool again=1;
  185. Course c;
  186. char catalogFilename[128]="catalog.dat";
  187. ifstream catalogIn(catalogFilename, ios_base::app);
  188. ofstream catalogOut(catalogFilename, ios_base::app);
  189. Course courseCatalog[256];
  190.  
  191. loadInCourses(catalogIn, courseCatalog);
  192.  
  193.  
  194. courseCatalog[getNumCourses(courseCatalog)+1]=addCourse();
  195.  
  196. loadOutCourses(catalogOut, courseCatalog);
  197.  
  198. return 0;
  199. }
  200.  
  201. #include "cc.h"
  202.  
  203. int displayMainMenu(){
  204. int choice;
  205. cout<<endl<<"**********MAIN MENU**********"<<endl;
  206. cout<<"1. Print List Schedule"<<endl;
  207. cout<<"2. Print Weekly Schedule"<<endl;
  208. cout<<"3. Get Course"<<endl;
  209. cout<<"4. Advanced Options"<<endl;
  210. cout<<"0 to Quit"<<endl;
  211. cout<<"*****************************"<<endl<<endl;
  212. cout<<"Menu Choice: ";
  213. cin>>choice;
  214. return choice;
  215. }
  216. int displayAdvMenu(){
  217. int choice;
  218. cout<<endl<<"**********ADV MENU**********"<<endl;
  219. cout<<"1. Add Course to Catalog"<<endl;
  220. cout<<"2. Remove Duplicates"<<endl;
  221. cout<<"0 to go Back"<<endl;
  222. cout<<"****************************"<<endl<<endl;
  223. cout<<"Menu Choice: ";
  224. cin>>choice;
  225. return choice;
  226. }
  227.  
  228. Course addCourse(){
  229. Course course;
  230.  
  231. cout<<"nCourse name:tt";
  232. cin.ignore();
  233. cin.getline(course.name, CNAMESIZE);
  234.  
  235. cout<<"Course ID:tt";
  236. cin.getline(course.id, CIDSIZE);
  237.  
  238. cout<<"Number of credits:t";
  239. cin>>course.credits;
  240.  
  241.  
  242.  
  243. /*<<"Enter semester: ";
  244. cin.getline(course.semester);
  245.  
  246. for(int i=0; i<PREREQ_SIZE && choice==1; i++){
  247. bool choice;
  248. cout<<"Add PreReq?: ";
  249. cin>>choice;
  250. if(choice==1){
  251. ...
  252. }
  253. }
  254.  
  255. for(int i=0; i<POSTREQ_SIZE && choice==1; i++){
  256. bool choice;
  257. cout<<"Add PostReq?: ";
  258. cin>>choice;
  259. if(choice==1){
  260. ...
  261. }
  262. } */
  263.  
  264. return course;
  265. }
  266.  
  267. void loadInCourses(ifstream & ifs, Course courseCatalog[]){
  268. cout<<"b*"<<endl<<courseCatalog[0];
  269. int i=0;
  270. while(ifs>>courseCatalog[i].credits){
  271. ifs.getline(courseCatalog[i].name, CNAMESIZE, ',');
  272. ifs.getline(courseCatalog[i].id, CIDSIZE, ',');
  273. ifs.getline(courseCatalog[i].professor, CPROFSIZE, ',');
  274. ifs.getline(courseCatalog[i].semester, CSEMSIZE, ',');
  275. ifs.get(courseCatalog[i].grade);
  276. i++;
  277. cout<<"d*"<<endl<<courseCatalog[i];
  278. }
  279. cout<<"c*"<<endl<<courseCatalog[0];
  280. return;
  281. }
  282.  
  283. void loadOutCourses(ofstream & ofs, Course courseCatalog[]){
  284. for(int i=0; i<=getNumCourses(courseCatalog); i++){
  285. ofs<<courseCatalog[i].credits<<
  286. courseCatalog[i].name<<","<<
  287. courseCatalog[i].id<<","<<
  288. courseCatalog[i].professor<<","<<
  289. courseCatalog[i].semester<<","<<
  290. courseCatalog[i].grade<<endl;
  291. }
  292. }
  293.  
  294. Course findCourse(ifstream & ifs){
  295. char attribute;
  296. string needle;
  297. int credits;
  298. int name;
  299. int id;
  300. bool again=1;
  301. int numLines = getNumLines(ifs);
  302.  
  303. cout<<"Search by (N)ame or (I)d? ";
  304. cin>>attribute;
  305. while(again){
  306. switch(attribute){
  307. case 'N': case 'n':
  308. cout<<"Enter name of course: ";
  309. cin>>name;
  310. for(int i=0; i<numLines; i++){
  311.  
  312. }
  313. break;
  314. case 'I': case 'i':
  315. cout<<"Enter course ID: ";
  316. cin>>id;
  317. break;
  318. default:
  319. cout<<"Invalid Attribute. Try Again."<<endl;
  320. }
  321. }
  322. }
  323.  
  324. int getNumCourses(Course courseCatalog[]){
  325. int numcourses=0;
  326. for(int i=0;courseCatalog[i].credits!=0;i++){
  327. numcourses++;
  328. }
  329. return numcourses;;
  330. }
  331.  
  332. int getNumLines(ifstream & ifs){
  333. char ch;
  334. int count=0;
  335.  
  336. while(ch=ifs.get()){
  337. count+=(ch=='n'?1:0);
  338. }
  339.  
  340. ifs.close();
  341. return count;
  342. }
  343.  
  344. ostream& operator<<(ostream& os, const Course c){
  345. os<<endl<<c.name<<endl<<c.id<<endl<<c.credits<<" cr hrs"<<endl;
  346. return os;
  347. }
  348.  
  349. #ifndef CC_H
  350. #define CC_H
  351.  
  352. #include <iostream>
  353. #include <fstream>
  354. #include <cstdlib>
  355. #include <cstring>
  356. using namespace std;
  357.  
  358. const int PREREQ_SIZE = 15;
  359. const int POSTREQ_SIZE = 15;
  360. const int CNAMESIZE=40;
  361. const int CIDSIZE=15;
  362. const int CPROFSIZE=40;
  363. const int CSEMSIZE=15;
  364.  
  365. struct Course{
  366. char name[CNAMESIZE];
  367. char id[CIDSIZE];
  368. int credits;
  369. char professor[CPROFSIZE];
  370. char semester[CSEMSIZE];
  371. char grade;
  372. float timeStart;
  373. float timeStop;
  374. friend ostream& operator<<(ostream& os, const Course c);
  375. };
  376.  
  377. Course addCourse();
  378. int displayMainMenu();
  379. int displayAdvMenu();
  380. void printString(Course c);
  381. void loadInCourses(ifstream & ifs, Course courseCatalog[]);
  382. void loadOutCourses(ofstream & ofs, Course courseCatalog[]);
  383. Course findCourse(ifstream & ifs);
  384. int getNumCourses(Course courseCatalog[]);
  385. int getNumLines(ifstream & ifs);
  386.  
  387. #endif /* CC_H */
  388.  
  389. void loadInCourses(ifstream & ifs, Course courseCatalog);
  390. void loadOutCourses(ofstream & ofs, Course courseCatalog);
  391.  
  392. void loadInCourses(ifstream & ifs, Course courseCatalog[]);
  393. void loadOutCourses(ofstream & ofs, Course courseCatalog[]);
  394.  
  395. Course (*courseCatalog)[]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement