当前位置:编程学习 > C#/ASP.NET >>

C#编写代码修改

// C#面向对象程序设计编程实例
//要求:请给学校教务管理系统设计一个教师类和学生类,其中,教师信息包括教师编号,教师姓名,年龄(0-80)、工资(工资>5000,税收为百分10,<2000税收为0,中间的为百分5)和所属学院;学生信息包括学号,学生姓名、年龄(0-60),所属班级和总成绩。
//然后,尝试引入一个基类,并使用基类来简化设计。 并编写程序调试验证。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Cool
{
private int no;
private string name;
private int age;
static void Main()
{}


public Cool(int no, string name, int age)
{

this.no = no;
this.name = name;
this.age = age;

Console.Write("请输入号码");
no= Console.Read();
Console.Write("请输入姓名");
name = Console.Read();
Console.Write("请输入年龄");
age = Console.Read();
}
public int no
{

get
{
return no;
}
set
{
no = value;
}
}
public int name
{
get
{
return name;
}
set
{
name = value;
}
}
public int age
{
get
{
return age;
}
set
{
age = value;
}
}

public class teacher : Cool
{
double wages;
int age;
public teacher(string id, string name)
: base(id, name)
{
if (0 < age < 80)
return age;
else
Console.Write("请输入0到80的年龄");
w = wages;
if (wages >= 5000)
w = wages * 0.9;
else if (wages > 2000 & wages < 5000)
w = wages * 0.95;
else
return wages;

}
public class student : Cool
{
int age;
int sclass;
float score;
public student(string id, string name)
: base(id, name)
{
if (0 < age < 60)
return age;
else

Console.Write("请输入0到60的年龄");
Console.Write("请输入班级");
sclass = Console.Read();
Console.Write("请输入成绩");
score = Console.Read();
}

}


}
static void Main(string[] args)
{
char w;
Console.Write("输入学生信息请按1,输入教师信息请按2");
w = Console.Read();
switch (w)
{
case 1: student(); break;
case 2: teacher(); break;
}
}
}
}

追问:不能在我的基础上修改么?
答案:using System.Collections.Generic;
using System.Text;
using System;

namespace WindowsApplication1
{
class Cool
{
private int no;
private string name;
private int age;

public Cool(int no, string name, int age)
{
this.no = no;
this.name = name;
this.age = age;

Console.Write("请输入号码");
no = Console.Read();
Console.Write("请输入姓名");
name = Console.ReadLine();
Console.Write("请输入年龄");
age = Console.Read();
}
public int No
{

get
{
return no;
}
set
{
no = value;
}
}
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}

public class teacher : Cool
{
double w;
double wages;
int age;
public teacher(int id, string name)
: base(id, name,0)
{
if (0 < age && age < 80)
{
}
else
{
Console.Write("请输入0到80的年龄");
}
w = wages;
if (wages >= 5000)
w = wages * 0.9;
else if (wages > 2000 & wages < 5000)
w = wages * 0.95;


}
public class student : Cool
{
int age;
int sclass;
float score;
public student(int id, string name)
: base(id, name,0)
{
if (0 < age && age < 60)
{

}

else
{
Console.Write("请输入0到60的年龄");
}
Console.Write("请输入班级");
sclass = Console.Read();
Console.Write("请输入成绩");
score = Console.Read();
}

}


}
static void Main(string[] args)
{
string w;
Console.Write("输入学生信息请按1,输入教师信息请按2");
w = Console.ReadLine();
switch (w)
{
case "1": new WindowsApplication1.Cool.teacher.student(0,""); break;
case "2": new teacher(0, ""); break;
}

Console.ReadLine();
}
}
}

分值太少了吧。这个类好麻烦
public Cool(int no, string name, int age)
{

this.no = no;
this.name = name;
this.age = age;

Console.Write("请输入号码");
no= Console.Read();
Console.Write("请输入姓名");
name = Console.Read();
Console.Write("请输入年龄");
age = Console.Read();
}
这里错了

上一个:关于C#的问题
下一个:关于C#的问题

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,