fork download
  1. #include <iostream>
  2.  
  3. #include <fstream>
  4.  
  5. #include <iomanip>
  6.  
  7. //include function libraries
  8. using namespace std;
  9. int main()
  10. {
  11. //declares all variables
  12.  
  13. string student, Address, phone, Years, ssn;
  14.  
  15. int Age;
  16.  
  17. double testone,testtwo, testthree, testfour, FinalExam, Average;
  18.  
  19. char lettergrade;
  20.  
  21. //declares ifstream and ofstream objects
  22.  
  23. ifstream inputfile;
  24.  
  25. ofstream outputfile;
  26.  
  27. //opens the txt files that the information will be taken from and written too.
  28.  
  29. inputfile.open("studentdata.txt");
  30.  
  31. outputfile.open("studentdataoutput.txt");
  32.  
  33. //set precision
  34. outputfile<<fixed<< setprecision(2);
  35.  
  36. //allows the computer to skip over whitespace in the file
  37. // to read name properly
  38.  
  39. getline(inputfile, student);
  40.  
  41. //continues to read the variables from the .txt file
  42. inputfile>> Age;
  43. inputfile.ignore();
  44. getline(inputfile, Address);
  45. inputfile >> Years;
  46. inputfile >> phone;
  47. inputfile >> ssn;
  48. inputfile >> testone;
  49. inputfile >> testtwo;
  50. inputfile >>testthree;
  51. inputfile >>testfour;
  52. inputfile >> FinalExam;
  53.  
  54. //the program is outputting all the information to the text file
  55. //setw to align all the items
  56. outputfile <<setw(45)<< "Student Grade Sheet" << endl;
  57. outputfile <<setw(35)<<"Name of Student:" << " " <<student << endl;
  58. outputfile <<setw(35)<< "Age:" << " " <<Age << endl;
  59. outputfile <<setw(35)<< "Address:" << " " << Address <<endl;
  60. outputfile <<setw(35)<< "Number of years at Texas State:" << " " << Years<<endl;
  61. outputfile <<setw(35)<< "Telephone Number:" << " " << phone<< endl;
  62. outputfile <<setw(35)<< "Student Social Security #:" << " " << ssn<<endl;
  63. outputfile <<setw(35)<< "Test #1:" << "
  64. outputfile <<setw(35)<< "Test #2:" << "
  65. outputfile <<setw(35)<< "Test #3:" << "
  66. outputfile <<setw(35)<< "Test #4:" << "
  67. outputfile <<setw(35)<< "Final Exam:" << "
  68.  
  69. //calculates the average of all exams
  70. " << testone<<endl;
  71. " << testtwo<< endl;
  72. " <<testthree<<endl;
  73. " <<testfour<<endl;
  74. " << FinalExam<<endl;
  75. Average=(testone*.1)+(testtwo*.15)+(testthree*.15)+(testfour*.20)+(FinalExam*.40);
  76.  
  77. // if and else statements to convert the average to a letter grade
  78. //
  79. if (Average < 60)
  80. {
  81. lettergrade = 'F';
  82. }
  83. else if (Average < 70)
  84. {
  85. lettergrade = 'D';
  86. }
  87. else if (Average < 80)
  88. {
  89. lettergrade = 'C';
  90. }
  91. else if (Average < 90)
  92. {
  93. lettergrade = 'B';
  94. }
  95. else
  96. {
  97. lettergrade = 'A';
  98. }
  99. outputfile << setw(35)<< "Your letter grade is: " << lettergrade << endl;
  100.  
  101. // closes both files that were read from and written too
  102. inputfile.close();
  103. outputfile.close();
  104.  
  105. //returns control to the operating system
  106. return 0;
  107.  
  108. }
  109.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:63:39: warning: missing terminating " character [enabled by default]
 outputfile <<setw(35)<< "Test #1:" << "
                                       ^
prog.cpp:63:1: error: missing terminating " character
 outputfile <<setw(35)<< "Test #1:" << "
 ^
prog.cpp:64:39: warning: missing terminating " character [enabled by default]
 outputfile <<setw(35)<< "Test #2:" << "
                                       ^
prog.cpp:64:1: error: missing terminating " character
 outputfile <<setw(35)<< "Test #2:" << "
 ^
prog.cpp:65:39: warning: missing terminating " character [enabled by default]
 outputfile <<setw(35)<< "Test #3:" << "
                                       ^
prog.cpp:65:1: error: missing terminating " character
 outputfile <<setw(35)<< "Test #3:" << "
 ^
prog.cpp:66:39: warning: missing terminating " character [enabled by default]
 outputfile <<setw(35)<< "Test #4:" << "
                                       ^
prog.cpp:66:1: error: missing terminating " character
 outputfile <<setw(35)<< "Test #4:" << "
 ^
prog.cpp:67:42: warning: missing terminating " character [enabled by default]
 outputfile <<setw(35)<< "Final Exam:" << "
                                          ^
prog.cpp:67:1: error: missing terminating " character
 outputfile <<setw(35)<< "Final Exam:" << "
 ^
prog.cpp:70:1: warning: missing terminating " character [enabled by default]
 " << testone<<endl;
 ^
prog.cpp:70:1: error: missing terminating " character
prog.cpp:71:1: warning: missing terminating " character [enabled by default]
 " << testtwo<< endl;
 ^
prog.cpp:71:1: error: missing terminating " character
prog.cpp:72:1: warning: missing terminating " character [enabled by default]
 " <<testthree<<endl;
 ^
prog.cpp:72:1: error: missing terminating " character
prog.cpp:73:1: warning: missing terminating " character [enabled by default]
 " <<testfour<<endl;
 ^
prog.cpp:73:1: error: missing terminating " character
prog.cpp:74:4: warning: missing terminating " character [enabled by default]
    " << FinalExam<<endl;
    ^
prog.cpp:74:4: error: missing terminating " character
prog.cpp: In function ‘int main()’:
prog.cpp:75:8: error: no match for ‘operator=’ (operand types are ‘std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}’ and ‘double’)
 Average=(testone*.1)+(testtwo*.15)+(testthree*.15)+(testfour*.20)+(FinalExam*.40);
        ^
prog.cpp:75:8: note: candidate is:
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:58:11: note: std::basic_ostream<char>& std::basic_ostream<char>::operator=(const std::basic_ostream<char>&) <deleted>
     class basic_ostream : virtual public basic_ios<_CharT, _Traits>
           ^
/usr/include/c++/4.8/ostream:58:11: note:   no known conversion for argument 1 from ‘double’ to ‘const std::basic_ostream<char>&’
stdout
Standard output is empty