Note that there are some explanatory texts on larger screens.

plurals
  1. POCANNOT COMPILE:: I don't understand my errors. Mostly the "declared as void" errors and "StudentType was not declared in this scope".
    text
    copied!<p><strong>I keep receiving these errors when I run the compiler:</strong></p> <pre><code>Program04.cpp:21:14: error: variable or field âgetDataâ declared void Program04.cpp:21:14: error: âStudentTypeâ was not declared in this scope Program04.cpp:21:26: error: expected primary-expression before â]â token Program04.cpp:21:29: error: expected primary-expression before âintâ Program04.cpp:23:15: error: variable or field âsortDataâ declared void Program04.cpp:23:15: error: âStudentTypeâ was not declared in this scope Program04.cpp:23:27: error: expected primary-expression before â]â token Program04.cpp:23:30: error: expected primary-expression before âintâ Program04.cpp:27:22: error: variable or field âcomputeAveragesâ declared void Program04.cpp:27:22: error: âStudentTypeâ was not declared in this scope Program04.cpp:27:34: error: expected primary-expression before â]â token Program04.cpp:27:37: error: expected primary-expression before âintâ Program04.cpp:29:16: error: variable or field âprintDataâ declared void Program04.cpp:29:16: error: âStudentTypeâ was not declared in this scope Program04.cpp:29:28: error: expected primary-expression before â]â token Program04.cpp:29:31: error: expected primary-expression before âintâ Program04.cpp: In function âint main()â: Program04.cpp:34:1: error: âStudentTypeâ was not declared in this scope Program04.cpp:34:13: error: expected â;â before âstudentsâ Program04.cpp:37:9: error: âstudentsâ was not declared in this scope Program04.cpp:37:19: error: ânâ was not declared in this scope Program04.cpp:37:20: error: âgetDataâ was not declared in this scope Program04.cpp:38:21: error: âsortDataâ was not declared in this scope Program04.cpp:39:25: error: âcomputeAveragesâ was not declared in this scope Program04.cpp:40:19: error: âprintDataâ was not declared in this scope Program04.cpp: At global scope: Program04.cpp:45:14: error: variable or field âgetDataâ declared void Program04.cpp:45:14: error: âStudentTypeâ was not declared in this scope Program04.cpp:45:38: error: expected primary-expression before âintâ </code></pre> <p><strong>Everything looks good to me, so i'm obviously not understanding something. Any suggestions?</strong></p> <hr> <p>PROGRAM FILE</p> <hr> <pre><code>using namespace std; #include "StudentType.h" #include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;fstream&gt; #include &lt;climits&gt; #include &lt;string&gt; const int MAX_STDS = 20; void getData(StudentType[], int&amp;); void sortData(StudentType[], int&amp;); void getFormat(string&amp;); void computeAverages(StudentType[], int&amp;); void printData(StudentType[], int&amp;); int main () { StudentType students[MAX_STDS]; StudentType(); getData(students, n); sortData(students, n); computeAverages(students); printData(students); return 0; } void getData(StudentType students[], int n){ ifstream fin; int grade; string filename, name; bool done = false; cout &lt;&lt; "Enter filename: "; cin &gt;&gt; filename; fin.open(filename.c_str()); while(true) { try { fin.open(filename.c_str()); if(!fin) { throw(string("Could not open " + filename + ".")); } break; } catch (string s) { cout &lt;&lt; s &lt;&lt; endl; cout &lt;&lt; "Enter a different file name: "; cin &gt;&gt; filename; } } n=0; while(n&lt;MAX_STDS &amp;&amp; getline(fin, name)) { students[n].setName(getFormat(name)); for(int i = 0; i &lt; NUM_GRDS; ++i) { fin &gt;&gt; grade; student[n].setGrade(grade, i); } getline(fin, name); ++n; } } void printData(StudentType students[], int n) { for(int i = 0; i &lt; n; ++i) { students[i].printLine(); } } void computeAverages(StudentType students[], int n) { for(int i = 0; i &lt; n; ++i) { students[i].computeAverage(); } } void sortData(StudentType students[], int n) { for(int i=0; i&lt;n-1; i++) { for(int j=0; j &lt; n-1-i; ++j) { if(students[j].getName() &gt; students[j+1].getName()) { swap(students[j], students[j+1]); } } } } void getFormat(string&amp; name) { string first; string middle; string last; char n, m; int size = 0; n = name.find(' '); first = name.substr(0, n); m = name.find(' ', n + 1); size = name.size(); if (m != string::npos) { middle = name.substr(n+1, m-(n+1)); last = name.substr(m+1, size - (m+1)); } else { middle = ""; last = name.substr(n + 1, size - (n + 1)); } name = last + ", " + first; if (middle != "") { name = (name + ' ') + middle[0]; } } </code></pre> <hr> <p>HEADER FILE</p> <hr> <pre><code>#ifdef STUDENTTYPE__H #define STUDENTTYPE__H #include &lt;string&gt; #include&lt;iostream&gt; const int NUM_GRDS = 10; class StudentType { public: StudentType(); void setName(std::string); void setGrade(int, int); void computeAverage(); std::string getName() const; void print(std::ostream&amp; = std::cout) const; private: std::string name; int grades[NUM_GRDS]; float avg; }; #endif </code></pre> <hr> <p>IMPLEMENTATION FILE</p> <hr> <pre><code>#include "StudentType.h" #include &lt;iomanip&gt; StudentType::StudentType(){ name = ""; for(int i =0; i &lt;NUM_GRDS; ++i){ grades[i] = 0; } avg = 0.0; } void StudentType::setName(std::string newName){ name = newName; } void StudentType::setGrade(int grade, int num){ grades[num] = grade; } void StudentType::computeAverage(){ float total = 0; for(int i = 0; i&lt;NUM_GRDS; ++i){ total += grades[i]; } avg = total/NUM_GRDS; } std::string StudentType::getName() const{ return name; } void StudentType::printLine(std::ostream&amp; out) const { out.setf(std::left); out.setf(std::fixed); out.setf(std::showpoint); out &lt;&lt; "\n" &lt;&lt; setw(25) &lt;&lt; "Student" &lt;&lt; setw(50) &lt;&lt; "Grades" &lt;&lt; setw(10) &lt;&lt; "Average" &lt;&lt; endl; out &lt;&lt; "_____________________________________________________________________________________" &lt;&lt; endl; out &lt;&lt; std::left &lt;&lt; std::setw(25) &lt;&lt; name &lt;&lt; std::right &lt;&lt; ' '; for(int i = 0; i &lt; NUM_GRDS; ++i){ out &lt;&lt; std::setw(5) &lt;&lt; grades[i] &lt;&lt; ' '; } out &lt;&lt; setprecision(2) &lt;&lt; std::setw(6) &lt;&lt; avg &lt;&lt; endl; } </code></pre> <hr> <p><strong>My output should look like this after the program compiles...</strong></p> <hr> <pre><code>Enter file name: grades.dat Student Grades Average ________________________________________________________________________________________ Last, First 90 80 70 60 50 40 30 20 10 0 45.00 Last, First 40 40 40 40 40 40 40 40 40 40 40.00 Last, First 54 98 65 32 21 87 54 65 98 32 60.60 Flames, Blood A 9 8 7 6 5 4 3 2 1 0 4.50 Bottoms, Car 32 65 98 87 54 24 56 89 78 68 65.10 Guitars, Dean 10 10 10 10 10 10 10 10 10 10 10.00 Honer, Ruth T 78 56 12 23 45 89 31 64 97 79 57.40 Hot, Zepher R 12 54 87 89 56 32 51 46 97 31 55.50 . . . </code></pre> <p><strong>The input file should have this format and include over 20 students for testing purposes: g0, g1,...g9 should be 10 grades ranging from 0 to 100</strong></p> <pre><code>First Middle Last g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 First Last g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload