#include <stdio.h>
// 定义基类
typedef struct {
double base_salary;
} Employee;
// 定义三个子类,分别为教授、副教授和职工
typedef struct {
Employee employee;
double teaching_hours;
} Professor;
typedef struct {
Employee employee;
double teaching_hours;
} AssociateProfessor;
typedef struct {
Employee employee;
double work_hours;
} Staff;
// 定义子类的方法,用于计算课时工资
double calculate_teaching_salary(double teaching_hours) {
return teaching_hours * 50.0; // 假设每个小时的课时工资为 50 元
}
double calculate_work_salary(double work_hours) {
return work_hours * 30.0; // 假设每个小时的工时工资为 30 元
}
int main() {
// 实例化三个子类对象,并调用子类的方法计算工资
Professor professor = {{5000.0}, 80.0};
double professor_salary = professor.employee.base_salary + calculate_teaching_salary(professor.teaching_hours);
printf("Professor salary: %f\n", professor_salary);
AssociateProfessor associate_professor = {{4000.0}, 60.0};
double associate_professor_salary = associate_professor.employee.base_salary + calculate_teaching_salary(associate_professor.teaching_hours);
printf("Associate professor salary: %f\n", associate_professor_salary);
Staff staff = {{3000.0}, 120.0};
double staff_salary = staff.employee.base_salary + calculate_work_salary(staff.work_hours);
printf("Staff salary: %f\n", staff_salary);
return 0;
}
把这些类的定义给出来看下你纯虚函数继承的时候是不是没有实现,还是其他什么错误
#include<stdio.h>
//x + 1;//不带副作用
//x++;//带有副作用
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main()
{
int x = 5;
int y = 8;
int z = MAX(x++, y++);
printf("x=%d y=%d z=%d\n", x, y, z);//输出的结果是什么?
return 0;
}