磨花眼镜 2020-06-02 00:16 采纳率: 50%
浏览 108
已采纳

求求大佬们帮我看看哪错了?

请设计并实现一个学生类,其中学生的信息包括:

姓名(char *name),学号(char id[]),年龄(int age), 住址(string)。

该类对外提供的接口功能包括:

1.构造函数:初始化学生类对象(无参构造,有参构造,拷贝构造,至少3种)
2.普通函数:获取学生信息,修改学生信息,输出学生信息

3.析构函数:释放学生类对象内存空间

要求:
1)在主函数中定义多个学生类的对象,并采用不同形式实现对类对象的初始化。

2)阐述普通构造函数(传值初始化新对象),拷贝构造函数(对象初始化对象)在初始化对象过程中的联系与区别。

## # #include <iostrea
using namespace std;

#include <cstring

class student
{
public:

 int id,age;char name[11],adress[21];
 student(char *name,char *adress,int age,int id)

{

    name="lisi";
    adress="龙门";
    age=21;
   id=001;
}
student()
{
    name="zhangshan";
    adress="东国";
    age=23;
    id=123; 
}
void Show( )
{
    cout << " The student’s name: " << name << endl;
    cout << "The student’s id: " << id << endl;
    cout << "The student’s age: " << age << endl;
     cout << "The student’s adress: " << adress << endl;
}

void modify()

{ cout<<"修改姓名为:" ;  cin>>name; cout<<endl; 
  cout<<"修改学号为:" ;  cin>>id;   cout<<endl; 
  cout<<"修改年龄为:" ;  cin>>age;   cout<<endl;

cout<<"修改学生地址为:" ; cin>>adress; cout<<endl;
}

~student()
{

cout<<"这次可以的"<<endl; 

}

};

int main( )

{

cout<<"输出学生基本信息"<<endl; 
    student.Show( );                  //输出学生信息
student.modify();
cout<<"输出学生基本信息"<<endl;
student.Show( );
cout<<"输出学生数据信息"<<endl;
student.Show();
return 0;

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-06-02 09:36
    关注

    头文件不完整

    #include <iostream>
    using namespace std;
    #include <string>
    #include <cstring>
    

    对象需要先实例化。

    int main( )
    {
        student s("名字", "地址", 10, 123);
        cout<<"输出学生基本信息"<<endl; 
        s.Show( );                  //输出学生信息
        s.modify();
        cout<<"输出学生基本信息"<<endl;
        s.Show( );
        cout<<"输出学生数据信息"<<endl;
        s.Show();
        return 0;
    }
    

    问题解决的话,请点下采纳

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)