注册 登录
编程论坛 C++教室

各位大侠帮我找找错

王大元 发布于 2010-05-24 23:01, 892 次点击
#include "stdafx.h"
#include "iostream.h"
class student{
private:
    char name;
        int age;
public:
    char sex;
    void shouw()
    {cout<<"print student' name.age.sex"<<name<<age<<sex<<endl;}};
    student::shouw(){
        name='w';
        age=20;
        sex='m';}

    class correspond :public student{
    private:
        char major;
    public:
        void show()
        {cout<<'print major'<<major<<endl;}};
        corrspond::show(){
            major='C';}

int main(int argc, char* argv[])
{
    student m1();
    m1.shouw();
    corrspond n1();
    n1.show();
    return 0;
};
10 回复
#2
最近不在2010-05-25 00:05
程序代码:
// Note:Your choice is C++ IDE
#include <iostream>
using namespace std;
class stu
{
private:
    int m_age;
    char m_sex;
    char m_name;

public:
    stu()   
    {
        m_age = 20;
        m_sex = m;
        m_name[15] = 'l'
    }
    stu(int age, char sex, char name)
    {
        m_age = age;
        m_sex = sex;
        m_name = name;
    }
    void show()
    {
        cout<<"年纪:"<<m_age<<endl;
        cout<<"性别:"<<m_sex<<endl;
        cout<<"姓名:"<<m_sex<<endl;
    }   
};
#3
rong8622010-05-25 00:56
程序代码:
//#include "stdafx.h"
#include "iostream.h"
class student
{
private:
    char name;
    int age;
public:
    char sex;
    student();
    void shouw(){cout<<"print student' name.age.sex"<<name<<age<<sex<<endl;}
};

student::student()
{
        name='w';
        age=20;
        sex='m';
}


 class correspond :public student

 {
    private:
        char major;
    public:
        correspond();
        void show(){cout<<"print major"<<major<<endl;}

 };
correspond::correspond()
{
    major='C';
}

int main(int argc, char* argv[])
{
    student m1;
    m1.shouw();
    correspond n1;
    n1.show();
    return 0;
}
你怎么连类名都写错  
#4
王大元2010-05-25 08:31
回复 2楼 最近不在
哪里错了,我还是没找到原因啊
#5
咚呱咚呱2010-05-30 11:37
#include "stdafx.h"
#include "iostream.h"
应该是
#include <stdafx.h>
#include <iostream.h>
吧?
#6
bccn2502010-05-30 12:42
#include "stdafx.h"
#include "iostream.h"
class student{
private:
    char name;
        int age;
public:
    char sex;
    void shouw()
    {cout<<"print student' name.age.sex"<<name<<age<<sex<<endl;}};
    student::shouw(){            //好像要写返回值类型void吧
        name='w';
        age=20;
        sex='m';}

    class correspond :public student{
    private:
        char major;
    public:
        void show()
        {cout<<'print major'<<major<<endl;}};
        corrspond::show(){                //和上面一样
            major='C';}

int main(int argc, char* argv[])
{
    student m1();                        //可能可以不带括号吧,不知道加括号有没有错
    m1.shouw();
    corrspond n1();                        //同上
    n1.show();
    return 0;
};
#7
huannet2010-05-31 10:38
比我厉害..~
#8
王大元2010-06-03 13:27
回复 7楼 huannet
我也不是很会,还有很多不会,共勉吧
#9
王大元2010-06-03 13:28
回复 5楼 咚呱咚呱
这个好像都可以的
#10
bccn2502010-06-03 18:35
//#include "stdafx.h"    //这句去掉吧,好像没什么用
#include "iostream.h"
class student{
private:
    char name;
        int age;
public:
    char sex;
    void shouw()
    {cout<<"print student' name.age.sex"<<name<<age<<sex<<endl;}};   //这里已经写出函数体了,后面再写就是重复了
//   student::shouw(){            //如果这里写函数体的话最好前面加上void
//        name='w';
//        age=20;
//       sex='m';}          //上面已经有函数体了,这里就不要再写了,如果这里写的话,上面的函数体就删 掉

    class correspond :public student{        //下面的对像类型名,和这个不一样
    private:
        char major;
    public:
        void show()
          {cout<<"print major"<<major<<endl;}};
//        {cout<<'print major'<<major<<endl;}}; //1.字符串请用双引号    2.这里已经写出函数体了,后面再写就是重复了
//        corrspond::show(){    //1.如果这里写函数体的话最好加上void    2.还有就是这个类名拼写错了是 correspond 你自己写的类名,要看清楚点
//          major='C';}  //上面已经有函数体了,这里就不要再写了,如果这里写的话,上面的函数体就删掉

int main(int argc, char* argv[])
{
//    student m1();//不要加括号
    student m1;
    m1.shouw();
//    corrspond n1();  //1.拼写错了和上面那个类名不一样应该是 correspond 吧  2.不要加括号
    correspond n1;
    n1.show();
    return 0;
};


[ 本帖最后由 bccn250 于 2010-6-3 18:49 编辑 ]
#11
王大元2010-06-06 12:24
哇这么多错啊
1