代码无法执行,自己无法修改至能够运行
#include<iostream>
#include<string.h>
using namespace std;
class Student
{
private:
string name;
string sex;
double instantFee, //现有班费、收入、支出、总班费
public:
int i = 0;
Student(string n = "", string s = "", double ins = 0.0)
{
name = n;
sex = s;
instantFee = ins;
}
~Student()
{
cout << name << "的析构函数调用成功" << endl;
}
void informationInput(Student stu[])//输入基本信息
{
cin >> i;
cout << "请输入学生的姓名、性别、现有班费" << endl;
cin >> "姓名:" >> stu[i].name >> "性别: " >> stu[i].sex >> "现有班费: " >> stu[i].instantFee >> endl;
}
void informationShow(Student stu[])//输出基本信息
{
cin >> i;
cout << "姓名:" << stu[i].name << endl;
cout << "性别:" << stu[i].sex << endl;
cout << "现有班费:" << stu[i].instantFee << endl;
}
void informationDelete(Student& stu[])//删除基本信息
{
cin >> i;
free(stu[i]);
}
double feeDecrease();//班费支出
double feeIncrease();//班费收入
double feeSummary();//总班费
};
double income = 0.0, outcome = 0.0, summary = 0.0;
double Student::feeDecrease(double& outcome,Student stu[])
{
int i = 0;
cin >> i;
cout << "请输入学生及班费的支出" << endl;
stu[i].instantFee -= stu[i].outcome;
return instantFee;
}
double Student::feeIncrease(double& income,Student stu[])
{
int i = 0;
cin >> i;
cout << "请输入学生及班费的收入" << endl;
stu[i].instantFee += stu[i].income;
return instantFee;
}
void Student::feeSummary(Student& stu[])
{
for (int i = 1;i <= 5;i++)
{
summary += student[i].instantFee;
}
cout << summary << endl;
}
int main()
{
Student stu[5];
informationInput();
for (int i = 0; i < 5; i++)
{
stu[i].informationShow;
}
feeSummary();
feeIncrease(300.0,stu);
cout << stu[2].instantFee;
feeSummary();
feeDecrease(100.0,stu);
cout << stu[2].instantFee;
feeSummary();
system("pause");
return 0;
}
无法运行
纠错后能够运行并且最好能完善一下功能
#include<iostream>
#include<string.h>
using namespace std;
class Student
{
public:
string name;
string sex;
double instantFee; //现有班费、收入、支出、总班费
public:
int i = 0;
Student(string n = "", string s = "", double ins = 0.0)
{
name = n;
sex = s;
instantFee = ins;
}
~Student()
{
cout << name << "的析构函数调用成功" << endl;
}
void informationInput()//输入基本信息
{
cin >> i;
cout << "请输入学生的姓名、性别、现有班费" << endl;
cin >> name >> sex >> instantFee;
}
void informationShow()//输出基本信息
{
cin >> i;
cout << "姓名:" << this->name << endl;
cout << "性别:" << this->sex << endl;
cout << "现有班费:" << this->instantFee << endl;
}
void informationDelete()//删除基本信息
{
cin >> i;
free(this);
}
double feeDecrease(double outcome, Student stu[]);//班费支出
double feeIncrease(double income, Student stu[]);//班费收入
double feeSummary(Student stu[]);//总班费
};
double income = 0.0, outcome = 0.0, summary = 0.0;
double Student::feeDecrease(double outcome, Student stu[])
{
int i = 0;
cin >> i;
cout << "请输入学生及班费的支出" << endl;
stu[i].instantFee -= outcome;
return instantFee;
}
double Student::feeIncrease(double income, Student stu[])
{
int i = 0;
cin >> i;
cout << "请输入学生及班费的收入" << endl;
stu[i].instantFee += income;
return instantFee;
}
double Student::feeSummary(Student stu[])
{
for (int i = 1; i <= 5; i++)
{
summary += stu[i].instantFee;
}
cout << summary << endl;
return summary;
}
int main()
{
Student stu[5];
//stu[0].informationInput();
for (int i = 0; i < 5; i++)
{
stu[i].informationInput();
stu[i].informationShow();
stu[i].feeSummary(stu);
stu[i].feeIncrease(300.0, stu);
cout << stu[i].instantFee;
stu[i].feeSummary(stu);
stu[i].feeDecrease(100.0, stu);
cout << stu[i].instantFee;
stu[i].feeSummary(stu);
}
system("pause");
return 0;
}
看过了,3楼的可行
#include <iostream>
#include <string>
using namespace std;
class Student
{
private:
string name;
string sex;
double instantFee; //现有班费、收入、支出、总班费
public:
Student(string n = "", string s = "", double ins = 0.0)
{
name = n;
sex = s;
instantFee = ins;
}
~Student()
{
cout << name << "的析构函数调用成功" << endl;
}
double getInstantFee() // 获取班费
{
return instantFee;
}
void informationInput()//输入基本信息
{
cout << "请输入学生的姓名、性别、现有班费" << endl;
cin >> name;
cin >> sex;
cin >> instantFee;
}
void informationShow()//输出基本信息
{
cout << "姓名:" << name << endl;
cout << "性别:" << sex << endl;
cout << "现有班费:" << instantFee << endl;
}
double feeDecrease(double& outcome);//班费支出
double feeIncrease(double& income);//班费收入
};
double Student::feeDecrease(double& outcome)
{
instantFee -= outcome;
return instantFee;
}
double Student::feeIncrease(double& income)
{
instantFee += income;
return instantFee;
}
void feeSummary(Student (&stu)[5], int size)
{
double summary = 0.0;
for (int i = 1; i <= size;i++)
{
summary += stu[i].getInstantFee();
}
cout << summary << endl;
}
int main()
{
Student stu[5];
for (int i = 0; i < 5; ++i) {
cout << "请输入第" << (i + 1) << "名学生的姓名、性别、现有班费" << endl;
stu[i].informationInput();
}
for (int i = 0; i < 5; i++)
{
cout << "第" << (i + 1) << "名学生信息" << endl;
stu[i].informationShow();
}
feeSummary(stu, 5);
int i = 0;
double fee = 0.00;
cout << "请输入学生及班费的收入" << endl;
cin >> i;
cin >> fee;
cout << "学生现有班费: " << stu[i].feeIncrease(fee) << endl;
feeSummary(stu, 5);
cout << "请输入学生及班费的支出" << endl;
cin >> i;
cin >> fee;
cout << "学生现有班费: " << stu[i].feeDecrease(fee) << endl;
feeSummary(stu, 5);
system("pause");
return 0;
}
#include
#include<string.h>
using namespace std;
class Student
{
public:
string name;
string sex;
double instantFee; //现有班费、收入、支出、总班费
public:
int i = 0;
Student(string n = "", string s = "", double ins = 0.0)
{
name = n;
sex = s;
instantFee = ins;
}
~Student()
{
cout << name << "的析构函数调用成功" << endl;
}
void informationInput()//输入基本信息
{
cin >> i;
cout << "请输入学生的姓名、性别、现有班费" << endl;
cin >> name >> sex >> instantFee;
}
void informationShow()//输出基本信息
{
cin >> i;
cout << "姓名:" << this->name << endl;
cout << "性别:" << this->sex << endl;
cout << "现有班费:" << this->instantFee << endl;
}
void informationDelete()//删除基本信息
{
cin >> i;
free(this);
}
double feeDecrease(double outcome, Student stu[]);//班费支出
double feeIncrease(double income, Student stu[]);//班费收入
double feeSummary(Student stu[]);//总班费
};
double income = 0.0, outcome = 0.0, summary = 0.0;
double Student::feeDecrease(double outcome, Student stu[])
{
int i = 0;
cin >> i;
cout << "请输入学生及班费的支出" << endl;
stu[i].instantFee -= outcome;
return instantFee;
}
double Student::feeIncrease(double income, Student stu[])
{
int i = 0;
cin >> i;
cout << "请输入学生及班费的收入" << endl;
stu[i].instantFee += income;
return instantFee;
}
double Student::feeSummary(Student stu[])
{
for (int i = 1; i <= 5; i++)
{
summary += stu[i].instantFee;
}
cout << summary << endl;
return summary;
}
int main()
{
Student stu[5];
//stu[0].informationInput();
for (int i = 0; i < 5; i++)
{
stu[i].informationInput();
stu[i].informationShow();
stu[i].feeSummary(stu);
stu[i].feeIncrease(300.0, stu);
cout << stu[i].instantFee;
stu[i].feeSummary(stu);
stu[i].feeDecrease(100.0, stu);
cout << stu[i].instantFee;
stu[i].feeSummary(stu);
}
system("pause");
return 0;
}
你这个类定义的也不像个类啊
从代码来讲,比如57行,你输入个outcome,但代码里减去的却是结构里的outcome,那参数有啥用呢
报什么错,把报错信息发一下
代码缺点规范!
你目前出现的问题贴下
具体哪方面的报错可以贴一下,方便大家进行讨论
哪个步骤错了,贴一下,楼上贴了代码运行有没有问题,有问题再把问题贴出来大家讨论