2013-09-22 20 views
-3

我正在嘗試編寫一個成績冊程序。我正在定義一個成績冊的初級階段,這是一個結構向量,每個結構都有一個學生姓名和該學生成績向量的字符串。這裏是gradebook.h標題:獲取「預期標識符」和「缺少';'之前'。'「在類結構中

// Creates a gradebook database that can be accessed and modified 

#ifndef GRADEBOOK_H 
#define GRADEBOOK_H 
#include <string> 
#include <vector> 
#include <iostream> 
#include <fstream> 

using std::string; 
using std::vector; 
using std::cout; 
using std::cin; 
using std::endl; 

class gradebook { 
public: 
    //--constructors 
    gradebook(); 
    // post: An empty database is constructed 

    //--modifiers 
    void add_student(string name); 
    // post: A new student is added who has the given name 

    bool remove_student(string name); 
    // post: If the name matches an existing student, that student is removed. 
    // Otherwise, return false. 

    void add_grades(); 
    // post: Adds grades input from the keyboard 

    //--accessors 
    void show_total_grade(string name); 
    // post: Displays the cumulative grade for the student. If no student by 
    // that name, display a message conveying such. 

    void show_class_average(); 
    // post: Displays the average grade for the class. 

    void show_student_grade(string name); 
    // post: Displays grades for all assignemnts for the given student. 

    void show_assignment_grade(int assignment); 
    // post: Displays all the grades for the given assignment number. 

    //--iterator functions 

    struct book_entry 
    { 
     string my_name; 
     vector<double> grades; 

    book_entry(string name) 
    { 
     my_name = name; 
     vector<double> grades; 
    } 

    void get_student(string name) { 
     cout << my_name << ": "; 
     for (auto &i : grades) 
      cout << i << " "; 
     cout << endl; 

    } 
}; 

private: 
string my_student_name; 
string my_assignment; 
vector<book_entry> my_book; 
double my_grade; 
}; 

#endif 

和實現:

#include "gradebook.h" 
#include <vector> 
#include <string> 
#include <iostream> 

using std::string; 
using std::cout; 
using std::cin; 
using std::vector; 

//--constructors 
gradebook::gradebook() { 

vector<book_entry> my_book; 
} 
//--modifiers 
void gradebook::add_student(string name) { 
//my_book.next() = 
} 

//--accessors 
void gradebook::show_student_grade(string name) { 
book_entry.get_student(string name); 
} 

void gradebook::show_assignment_grade(int assignment) { 

} 

//--iterator functions 

我使用MSVS 2013年,當我生成項目,我得到落實的第23行錯誤(book_entry.get_student(string name);)。錯誤是「缺失」;「之前「。」該行中的句點有一個扭曲的紅色下劃線,如果我把它懸停在上面,我會得到一個不同的錯誤:「預期標識符」。看來我誤解了如何使用我設置的結構。我該如何解決?

+0

我該如何解決這個問題?它在最後一個花括號後面有一個分號。 – spartanhooah

+0

我有兩個;一個在結構的末尾,在private數據段之前,另一個在'#endif'之前。 – spartanhooah

回答

2

變化:

book_entry.get_student(string name); 

book_entry.get_student(name); 

此外,book_entry應該是這個範圍內有效的對象。你顯示的代碼沒有它,而是你的第一個代碼片斷說它是一個類型而不是一個對象。

+0

是的。這是一個問題。 – Maroun

+0

我做了這個改變,並且給'name'加下劃線,表示它不是一個類型名稱。至於你提出的第二個問題,我該如何改變? – spartanhooah

+0

這是此行的正確修復方法。看看你是否得到編譯器錯誤。您可能會困惑智能感知。 – drescherjm

相關問題