-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

book_entry.get_student(string name);我正在使用 MSVS 2013,当我构建项目时,我在实现 ( )的第 23 行收到错误。错误是“缺少';' 前 '。'”。该行中的句点有一个波浪形的红色下划线,如果我将鼠标悬停在它上面,我会得到一个不同的错误:“需要一个标识符”。看来我误解了如何使用我设置的结构。我该如何解决?

4

1 回答 1

2

改变:

book_entry.get_student(string name);

book_entry.get_student(name);

此外,book_entry应该是此范围内可用的对象。您显示的代码没有它,而是您的第一个代码片段说它是一个类型而不是一个对象。

于 2013-09-22T12:57:01.997 回答