Problem H: 设计整型链表类List

该程序包含两个部分:一是实现整型链表类List,包括插入、删除和打印操作;二是定义一个Salary类用于计算员工工资,包括基本工资、岗位工资等,并通过Worker类扩展实现员工姓名、年龄和部门的管理。程序演示了如何使用链表插入和删除节点,以及计算员工的实发工资。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Problem Description

设计一个整型链表类List,能够实现链表节点的插入(insert)、删除(delete),以及链表数据的输出操作(print)。

提示:链表结点用如下结构定义:
struct Node{//结点的结构
    int data;
    Node *next;
};

链表类List有一个数据成员head,类型是Node *

根据题目要求完善下面的程序:

#include<iostream>
using namespace std;

struct Node{//结点的结构
    int data;
    Node *next;
};

class List{
private:
    Node* head;
public:

//你的代码将被嵌在这里

int main()
{
    List list;//定义一个空链表list
    list.Listinsert(0,10);//在第0个结点的后面插入值为10的新结点,也即在链表头部插入新的结点
    list.Listinsert(0,66);
    list.Listinsert(1,292);//在第1个结点的后面插入值为10的新结点
    list.Listdelete(66);//删除链表中第一个值为66的结点
    list.Listinsert(2,-2);//在第2个结点的后面插入值为-2的新结点
    list.Listinsert(1,3);//在第1个结点的后面插入值为3的新结点
    list.Listprint();//从头到尾输出链表结点的值,每个输出值占一行
    return 0;
}

Sample Output

292
3
10
-2

 

#include <iostream>

#include <string>

using namespace std;

class Salary {

private:

	double Wage, Subsidy, Rent, WaterFee, ElecFee;//基本工资Wage,岗位工资Subsidy,房租Rent,水费WaterFee,电费ElecFee

public:

	Salary(double i1, double i2 = 0, double i3 = 0, double i4 = 0, double i5 = 0) {//初始化工资数据的各分项

		Wage = i1;

		Subsidy = i2;

		Rent = i3;

		WaterFee = i4;

		ElecFee = i5;

	}

	Salary() {//初始化工资的各分项数据为0

		Wage = Subsidy = Rent = WaterFee = ElecFee = 0;

	}

	void setWage(double f) { Wage = f; }

	double getWage() { return Wage; }



	void setSubsidy(double f) { Subsidy = f; }

	double getSubsidy() { return Subsidy; }



	void setRent(double f) { Rent = f; }

	double getRent() { return Rent; }



	void setWaterFee(double f) { WaterFee = f; }

	double getWaterFee() { return WaterFee; }



	void setElecFee(double f) { ElecFee = f; }

	double getElecFee() { return ElecFee; }



	double RealSalary() {//计算实发工资,实发工资=Wage+Subsidy-Rent-WaterFee-ElecFee

		return Wage + Subsidy - Rent - WaterFee - ElecFee;
	}

};

//你的代码将被嵌在这里
int m_Num = 0;
class Worker : public Salary
{
public:
	Worker(string name, int age, string dept)
	{
		m_name = name;
		m_age = age;
		m_Dept = dept;
		m_Num++;
	}
	Worker()
	{
		m_Num++;
	}
	int getNum()
	{
		return m_Num;
	}
	void setName(string name)
	{
		m_name = name;
	}
	string getName()
	{
		return m_name;
	}
	string m_name;
	int m_age;
	string m_Dept;
	Salary m_salary;
};
int main() {

	Worker w1("John", 30, "design");

	Worker w2;

	cout << "the total num is: " << w1.getNum() << endl;

	w2.setName("Linda");

	cout << "in w2 the name is: " << w2.getName() << endl;

	return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小木苓

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值