#include "stdafx.h"
#include "iostream"
using namespace std;
#include <string>
class Test
{
public:
int award[6];
string name;
int avg;
int pingyi;
char leader;
char west;
int paper;
public:
void input()
{cin>>name>>avg>>pingyi>>leader>>west>>paper;}
void yuanshijiangxuejin(){
if (avg>80)
{
if(paper>=1)
award[0]=8000;
else award[0]=0;
}else award[0]=0;
}
void wusijiangxuejin(){
if (avg>85)
{
if(pingyi>80)
award[1]=4000;
else award[1]=0;
}else award[1]=0;
}
void chengjiyouxiujiang(){
if (avg>90)
{
award[2]=2000;
}else{
award[2]=0;
}
}
void xibujiangxuejin(){
if (pingyi>80)
{
if(west=='y')
award[3]=1000;
else award[3]=0;
}else award[3]=0;
}
void banjigongxian(){
if (pingyi>80)
{
if (leader=='y')
award[4]=850;
else award[4]=0;
}else award[4]=0;
};
void main()
{ int i,max=0;
Test a;
a.input();
a.yuanshijiangxuejin();
a.wusijiangxuejin();
a.chengjiyouxiujiang();
a.xibujiangxuejin();
a.banjigongxian();
for(i=0;i<6;i++)
{
max+=award[i];
}
cout<<"奖金="<<max;
}
}
我用的是vs2010,求大神帮解决啊谢谢了
c++跟java不同,不能把main函数写在一个类里面。下面是改过的代码,编译通过
#include "iostream"
using namespace std;
#include <string>
class Test
{
public:
int award[6];
string name;
int avg;
int pingyi;
char leader;
char west;
int paper;
public:
void input()
{
cin >> name >> avg >> pingyi >> leader >> west >> paper;
}
void yuanshijiangxuejin(){
if (avg > 80)
{
if (paper >= 1)
award[0] = 8000;
else award[0] = 0;
}
else award[0] = 0;
}
void wusijiangxuejin(){
if (avg > 85)
{
if (pingyi > 80)
award[1] = 4000;
else award[1] = 0;
}
else award[1] = 0;
}
void chengjiyouxiujiang(){
if (avg > 90)
{
award[2] = 2000;
}
else{
award[2] = 0;
}
}
void xibujiangxuejin(){
if (pingyi > 80)
{
if (west == 'y')
award[3] = 1000;
else award[3] = 0;
}
else award[3] = 0;
}
void banjigongxian(){
if (pingyi > 80)
{
if (leader == 'y')
award[4] = 850;
else award[4] = 0;
}
else award[4] = 0;
}
};
void main()
{
int i, max = 0;
Test a;
a.input();
a.yuanshijiangxuejin();
a.wusijiangxuejin();
a.chengjiyouxiujiang();
a.xibujiangxuejin();
a.banjigongxian();
for (i = 0; i < 6; i++)
{
max += a.award[i];
}
cout << "奖金=" << max;
}