下面程序出现了一个错误,各位CSDN路过的朋友能否帮我看一下,我将以为数不多的分数相送。
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication
{
public static class GlobalMembers
{
static int Main()
{
string i = new string(new char[15]);
sbyte k;
string l = new string(new char[15]);
string m = new string(new char[15]);
sbyte j;
string n = new string(new char[15]);
string s = new string(new char[15]);
cin >> i >> j >> k;
cin >> l >> m;
cin >> n >> s;
CPeople a = new CPeople(ref i, j, k);
a.print();
CStudent b = new CStudent(ref i, j, k, ref l, ref m);
b.print();
CTeather c = new CTeather(ref i, j, k, ref n, ref s);
c.print();
return 0;
}
}
public class CPeople
{
protected string name = new string(new char[15]);
protected sbyte sex;
protected int age;
public CPeople(ref string a, sbyte b, int c)
{
name = a;
sex = b;
age = c;
}
public void print()
{
Console.Write("People:");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
}
}
public class CStudent : CPeople
{
protected string xh = new string(new char[20]);
protected string rxsj = new string(new char[20]);
public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
: base(ref a, b, c)
{
CPeople(a, b, c);
xh = d;
rxsj = e;
}
public new void print()
{
Console.Write("Student: ");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
Console.Write("No.: ");
Console.Write(xh);
Console.Write("\n");
Console.Write("Score: ");
Console.Write(rxsj);
Console.Write("\n");
}
}
public class CTeather : CPeople
{
protected string Position = new string(new char[10]);
protected string Department = new string(new char[10]);
public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
: base(ref a, b, c)
{
CPeople(a, b, c);
Position = d;
Department = e;
}
public new void print()
{
Console.Write("Student: ");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
Console.Write("Position: ");
Console.Write(Position);
Console.Write("\n");
Console.Write("Department: ");
Console.Write(Department);
Console.Write("\n");
}
}
public new void print()
{
Console.Write("Name: ");
Console.Write(base.name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(base.sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(base.age);
Console.Write("\n");
Console.Write("No.: ");
Console.Write(xh);
Console.Write("\n");
Console.Write("Score: ");
Console.Write(rxsj);
Console.Write("\n");
Console.Write("Position: ");
Console.Write(Position);
Console.Write("\n");
Console.Write("Department: ");
Console.Write(Department);
Console.Write("\n");
}
}
--------------------编程问答-------------------- --------------------编程问答-------------------- 贴了一大段代码 你还指望别人帮你运行起来调试?
--------------------编程问答-------------------- 最后一个void提示出错了。错误1 应输入 class、delegate、enum、interface 或 struct --------------------编程问答-------------------- 最后一个void提示出错了。错误1 应输入 class、delegate、enum、interface 或 struct --------------------编程问答-------------------- 何解? --------------------编程问答-------------------- 看了代码 我就懒得看了 但是 既然有"应输入 class、delegate、enum、interface 或 struct" 这个错误..
我目测的话 应该是多了一个}或者少了一个} --------------------编程问答--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication
{
public static class GlobalMembers
{
static int Main()
{
string i = new string(new char[15]);
sbyte k;
string l = new string(new char[15]);
string m = new string(new char[15]);
sbyte j;
string n = new string(new char[15]);
string s = new string(new char[15]);
cin >> i >> j >> k;
cin >> l >> m;
cin >> n >> s;
CPeople a = new CPeople(ref i, j, k);
a.print();
CStudent b = new CStudent(ref i, j, k, ref l, ref m);
b.print();
CTeather c = new CTeather(ref i, j, k, ref n, ref s);
c.print();
return 0;
}
}
public class CPeople
{
protected string name = new string(new char[15]);
protected sbyte sex;
protected int age;
public CPeople(ref string a, sbyte b, int c)
{
name = a;
sex = b;
age = c;
}
public void print()
{
Console.Write("People:");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
}
}
public class CStudent : CPeople
{
protected string xh = new string(new char[20]);
protected string rxsj = new string(new char[20]);
public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
: base(ref a, b, c)
{
CPeople(a, b, c);
xh = d;
rxsj = e;
}
public new void print()
{
Console.Write("Student: ");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
Console.Write("No.: ");
Console.Write(xh);
Console.Write("\n");
Console.Write("Score: ");
Console.Write(rxsj);
Console.Write("\n");
}
}
public class CTeather : CPeople
{
protected string Position = new string(new char[10]);
protected string Department = new string(new char[10]);
public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
: base(ref a, b, c)
{
CPeople(a, b, c);
Position = d;
Department = e;
}
public new void print()
{
Console.Write("Student: ");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
Console.Write("Position: ");
Console.Write(Position);
Console.Write("\n");
Console.Write("Department: ");
Console.Write(Department);
Console.Write("\n");
}
public new void print()
{
Console.Write("Name: ");
Console.Write(base.name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(base.sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(base.age);
Console.Write("\n");
Console.Write("No.: ");
Console.Write(xh);
Console.Write("\n");
Console.Write("Score: ");
Console.Write(rxsj);
Console.Write("\n");
Console.Write("Position: ");
Console.Write(Position);
Console.Write("\n");
Console.Write("Department: ");
Console.Write(Department);
Console.Write("\n");
}
}
}
运行下 是不是你想要的. --------------------编程问答-------------------- 提示出现了一个错误:错误 1 类型“ConsoleApplication.CTeather”已定义了一个名为“print”的具有相同参数类型的成员 --------------------编程问答-------------------- 如此人性化的错误提示信息,你居然还要来发帖问,你是汉语不过关,还是怎么的? --------------------编程问答-------------------- C#初学者,如何修改,能否指点一下? --------------------编程问答--------------------
方法和类是平行级别 --------------------编程问答-------------------- namespace ConsoleApplication1
{
public static class GlobalMembers
{
static int Main()
{
string i = new string(new char[15]);
sbyte k;
string l = new string(new char[15]);
string m = new string(new char[15]);
sbyte j;
string n = new string(new char[15]);
string s = new string(new char[15]);
cin >> i >> j >> k;
cin >> l >> m;
cin >> n >> s;
CPeople a = new CPeople(ref i, j, k);
a.print();
CStudent b = new CStudent(ref i, j, k, ref l, ref m);
b.print();
CTeather c = new CTeather(ref i, j, k, ref n, ref s);
c.print();
return 0;
}
}
public class CPeople
{
protected string name = new string(new char[15]);
protected sbyte sex;
protected int age;
public CPeople(ref string a, sbyte b, int c)
{
name = a;
sex = b;
age = c;
}
public void print()
{
Console.Write("Name:");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
}
}
public class CStudent : CPeople
{
protected string xh = new string(new char[20]);
protected string rxsj = new string(new char[20]);
public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
: base(ref a, b, c)
{
CPeople(a, b, c);
xh = d;
rxsj = e;
}
public new void print()
{
Console.Write("Student: ");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
Console.Write("No.: ");
Console.Write(xh);
Console.Write("\n");
Console.Write("Score: ");
Console.Write(rxsj);
Console.Write("\n");
}
}
public class CTeather : CPeople
{
protected string Position = new string(new char[10]);
protected string Department = new string(new char[10]);
public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
: base(ref a, b, c)
{
CPeople(a, b, c);
Position = d;
Department = e;
}
public new void print()
{
Console.Write("Teacher: ");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
Console.Write("Position: ");
Console.Write(Position);
Console.Write("\n");
Console.Write("Department: ");
Console.Write(Department);
Console.Write("\n");
}
}
}
LZ是想要这样的吗 --------------------编程问答-------------------- 这个我也不怎么清楚。 --------------------编程问答--------------------
namespace ConsoleApplication1
{
public static class GlobalMembers
{
static int Main()
{
string i = new string(new char[15]);
sbyte k;
string l = new string(new char[15]);
string m = new string(new char[15]);
sbyte j;
string n = new string(new char[15]);
string s = new string(new char[15]);
cin >> i >> j >> k;
cin >> l >> m;
cin >> n >> s;
CPeople a = new CPeople(ref i, j, k);
a.print();
CStudent b = new CStudent(ref i, j, k, ref l, ref m);
b.print();
CTeather c = new CTeather(ref i, j, k, ref n, ref s);
c.print();
return 0;
}
}
public class CPeople
{
protected string name = new string(new char[15]);
protected sbyte sex;
protected int age;
public CPeople(ref string a, sbyte b, int c)
{
name = a;
sex = b;
age = c;
}
public void print()
{
Console.Write("Name:");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
}
}
public class CStudent : CPeople
{
protected string xh = new string(new char[20]);
protected string rxsj = new string(new char[20]);
public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
: base(ref a, b, c)
{
CPeople(a, b, c);
xh = d;
rxsj = e;
}
public new void print()
{
Console.Write("Student: ");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
Console.Write("No.: ");
Console.Write(xh);
Console.Write("\n");
Console.Write("Score: ");
Console.Write(rxsj);
Console.Write("\n");
}
}
public class CTeather : CPeople
{
protected string Position = new string(new char[10]);
protected string Department = new string(new char[10]);
public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
: base(ref a, b, c)
{
CPeople(a, b, c);
Position = d;
Department = e;
}
public new void print()
{
Console.Write("Teacher: ");
Console.Write("\n");
Console.Write("Name: ");
Console.Write(name);
Console.Write("\n");
Console.Write("Sex: ");
Console.Write(sex);
Console.Write("\n");
Console.Write("Age: ");
Console.Write(age);
Console.Write("\n");
Console.Write("Position: ");
Console.Write(Position);
Console.Write("\n");
Console.Write("Department: ");
Console.Write(Department);
Console.Write("\n");
}
}
}
LZ是想要这样的吗
两个方法名字一模一样,即使你不是}多或少的错误你那里也肯定会报错的了,你这样的要求直接把Cpeople当做一个父类,下面的再按要求派生出子类就行了
补充:.NET技术 , C#