对于作业,我必须创建一个包含电影名称、MPAA 评级、从 1 到 5 评级的人数、找到每个评级的累积值和平均值的电影类。
我主要在构造函数和类方面遇到问题。我试图让它接受一个字符串(我得到了那部分有点正确)。我在第 77 行和第 83 行遇到了一些错误。我也被卡住了,因为我不知道下一步应该采取什么步骤。我将不胜感激任何可能的帮助。
这是我到目前为止得到的:
#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <string>
// Required headers
using namespace std;
//Class movie starts
class Movie {
public:
void SetMovieName(string moviename);
// Function to set the name of the movie
// moviename = movie; later on
string GetMPAAR();
//function to return the MPAA rating
int amountofratingsof1() const;
//function to return the number of people that rated the movie as a 1
int amountofratingsof2() const;
//function to return the number of people that rated the movie as a 2
int amountofratingsof3() const;
//function to return the number of people that rated the movie as a 3
int amountofratingsof4() const;
//function to return the number of people that rated the movie as a 4
int amountofratingsof5() const;
//function to return the number of people that rated the movie as a 5
int average() const;
//function to return the average value of all ratings
std::string Movies(string moviename = "Gavecube: The Movie");
//constructor to set the movie
private:
string Movie; //variable to store the name of the movie
int peoplethatrated1; // variable to store the number of people that rated 1
int peoplethatrated2; // variable to store the number of people that rated 2
int peoplethatrated3; // variable to store the number of people that rated 3
int peoplethatrated4; // variable to store the number of people that rated 4
int peoplethatrated5; // variable to store the number of people that rated 5
};
//implementation file:
void Movie::SetMovieName(const string moviename) {
//function below checks if it is a string or not
if (!cin) {
cout << "Not a valid input. Please restart." << endl;
}
}
int Movie::amountofratingsof1()const {
}
int Movie::amountofratingsof2()const {
}
int Movie::amountofratingsof3()const {
}
int Movie::amountofratingsof4()const {
}
int Movie::amountofratingsof5()const {
}
//constructor
std::string Movie(string moviename) {
SetMovieName(moviesname)
}
int main()
{
Movie Movies("Hello");
return 0;
}
谢谢你。