PurePureMilk

Class grades program

Jul 14th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. // ConsoleApplication7.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. #include <sstream>
  9. #include <stdlib.h>
  10.  
  11. using namespace std;
  12.  
  13.  
  14. int main()
  15. {
  16. ifstream infile;
  17. string line; // one line of text
  18. string token;
  19. int token_count = 0;
  20. int hw_total = 0;
  21.  
  22. infile.open("140-grades-1 asdf.txt");
  23.  
  24. if (!infile) {
  25. cout << "Could not open file to read. Exiting program" << endl;
  26. return -1;
  27. }
  28.  
  29. while (!infile.eof()) { //I don't understand what's !infile.eof(), look it up later
  30. getline(infile, line);
  31.  
  32. if (line[0] == '/') { //if the position 0 has '/' skip the line such as the first line in the text file
  33. // it's a comment line, skip
  34. continue;
  35. }
  36.  
  37. //DEBUG: cout << "line: " << line << endl;
  38.  
  39. stringstream ss(line); // turn line of text into a stream.... ehh still don't get what's ss(line)
  40.  
  41. while (getline(ss, token, ' ')) { //@_@ soo... ss would be the name??? OK I don't get the this part ss, token, ' '
  42. // cout << "tok: " << token << endl;
  43. switch (token_count)
  44. {
  45. case 0:
  46. cout << "Name: " << token;
  47. break;
  48. case 1:
  49. case 2:
  50. cout << "; HW: " << token;
  51. hw_total += stoi(token);
  52. }
  53. token_count++;
  54. }
  55. cout << "; Total: " << hw_total << endl;
  56. token_count = 0;
  57. hw_total = 0;
  58. }
  59.  
  60. infile.close();
  61.  
  62. cout << "done!" << endl;
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment