fork download
  1. /*The attached file is a historical record of BCS courses offered over the last four semesters. An X in one of the first four columns indicates that the course was offered in the semester that heads the column. A period (.) indicates that the course was not offered in that semester.
  2.  
  3. Read the file and store the following information in two vectors:
  4.  
  5. An integer that encodes the semester offerings for the course as follows; Fall 15 counts 8, Spring 16 counts 4, Fall 16 counts 2, and Spring 17 counts 1. The offering code is the sum of these four numbers.
  6. A string which saves the course number and title that follows after the four offering columns.
  7. The two vectors are parallel in the sense that a given subscript selects offering information and the description for the same course. E.g the subscript 0 selects offering information and the description for the first course in the file.
  8.  
  9. After reading, encoding and saving all the course information, display the number of courses read. Then list on cout
  10. */
  11.  
  12. #include <iostream>
  13. #include <string>
  14. #include <sstream>
  15. #include <fstream>
  16. #include <vector>
  17.  
  18. using std::cout;
  19. using std::string;
  20. using std::endl;
  21. using std::vector;
  22. int main()
  23. {
  24. const int F15 = 8, F16 = 2, S16 = 4, S17 = 1;
  25. string garbage, tempData;
  26. vector <int> codes;
  27. vector <string> courseInfo;
  28. std::istringstream test("F15 S16 F16 S17 \n . . . . BCS 101 Solving\n x x x x BCS 102 - Concepts");
  29. string fileName = "C:\\Users\\\\Downloads\\BCS-courses.txt";
  30. //std::ifstream theFile;
  31. //theFile.open(fileName);
  32. //if (!theFile)
  33. //{
  34. // cout << "Error reading file." << endl;
  35. //}
  36. std::getline(test, garbage);
  37. cout << garbage;
  38.  
  39.  
  40. for (int i = 0; i < 4; i++)
  41. {
  42. test >> tempData;
  43. if (tempData =="x")
  44. {
  45.  
  46. }
  47. }
  48.  
  49. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
F15 S16 F16 S17