所以我忙于我的任务,我写了一段完美运行的代码,但是,它还没有准备好。我能弄清楚的是如何在类中使用数组。或者如何获取和设置数组中的项目,以及我在哪里放置循环以提示用户输入标记。
所以我想提示用户输入3个赋值的赋值号和标记,存储在数组中,然后输出赋值和标记。我知道这听起来很愚蠢,但它会帮助我理解类中的数组。
我的课程在一个外部文件中
#ifndef ASSIGNMENTS_H_INCLUDED
#define ASSIGNMENTS_H_INCLUDED
#include<iostream>
using namespace std;
class assignments
{
public:
assignments(); // default constructor
void setAssNum(int k); // mutator
int getAssNum(); // accessor
void setAssMark(double m); // mutator
double getAssMark(); // accessor
private:
int AssNum;
double AssMark;
};
assignments::assignments()
{
AssNum = 0;
AssMark = 0.0;
}
void assignments::setAssNum(int k)
{
AssNum = k;
}
void assignments::setAssMark(double m)
{
AssMark = m;
}
int assignments::getAssNum()
{
return AssNum;
}
double assignments::getAssMark()
{
return AssMark;
}
#endif // ASSIGNMENTS_H_INCLUDED
这是主要的
int main()
{
int AssNum;
double AssMark;
assignments c;
cout <<"Enter Assignment Number: ";
cin >> AssNum;
cout <<"Enter Assignment Mark in Percentage: ";
cin >> AssMark;
c.setAssNum(AssNum);
c.setAssMark(AssMark);
cout <<"The Mark for assignment "<< c.getAssNum() <<" is: " << c.getAssMark()<<"%";
}
我不希望任何人重写代码,只是想清楚一点,如何在这种情况下使用数组。
谢谢