2000行之mother、father、child

//child.h
#ifndef CHILD_H
#define CHILD_H
#include <string>
using namespace std;
class Mother;
class Father;
class Child
{
public:
    Mother *mama;
    Father *baba;
    Child();
    string name;
    void answer();
    void callParent();
};

#endif // CHILD_H
//child.cpp
#include "child.h"
#include "mother.h"
#include "father.h"
#include <iostream>
using namespace std;
Child::Child():name("xiao Hua")
{
    //mama=new Mother;
    //baba=new Father;
}

void Child::answer(){
    cout<<endl<<name<<" is here!";
}

void Child::callParent()
{
    cout<<endl<<"I am calling my father!";
    cout<<endl<<"Father is not here!";
    //mama->answer();
    //baba->answer();
}
//mother.h
#ifndef MOTHER_H
#define MOTHER_H
#include <string>
using namespace std;
class Child;
class Mother
{
    Child *child;
    string name;
public:
    Mother();
    void callChild();
    void answer();
};

#endif // MOTHER_H
//mother.cpp
#include "mother.h"
#include "child.h"
#include <iostream>
using namespace std;
Mother::Mother():name("yyyyy")
{
    child=new Child;
}
void Mother::callChild(){
    cout<<endl<<"mama is calling my child!";
    child->answer();
}
void Mother::answer(){
    cout<<endl<<name<<" is here waiting for you!";
}
//father.h
#ifndef FATHER_H
#define FATHER_H

#include <string>
using namespace std;
class Child;
class Father
{
public:
    Father();
    string name;
    Child *child;
    void callChild();
    void answer();
};

#endif // FATHER_H
//father.cpp
#include "father.h"
#include "child.h"
#include <iostream>
using namespace std;
Father::Father():name("Lao Hua")
{
    child=new Child;
}

void Father::callChild(){
    cout<<endl<<"baba am calling my child!";
    child->answer();
}

void Father::answer(){
    cout<<endl<<name<<" is here waiting for you!";
}
//main.cpp
#include <QCoreApplication>
#include <iostream>
#include "father.h"
#include "child.h"
#include "mother.h"
using namespace std;
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    Child son;
    Father baba1;
    Mother mama1;
    son.callParent();
    baba1.callChild();
    mama1.callChild();
    cout<<endl;
    return a.exec();
}
时间: 2024-10-19 16:47:29

2000行之mother、father、child的相关文章

天才黑客!17岁打脸乔布斯,20岁搞疯索尼,26岁叫板特斯拉,写2000行代码市值8000万美金

文/创日报 今天说一个屌到飞起的黑客小哥! 扒他的时候创哥就觉得无比的欢快, 因为他的人生用三个字就能概括: “爽!爽!爽!” 不但颜值出众,智商更是卓绝! 89年出生,却把互联网巨头玩弄于股掌间, 17岁仅靠一把螺丝刀,破解了iPhone核心基带, 让iPhone变成了全网通. ▼ 无数人削尖脑袋都挤不进去的 “Google,SpaceX,Facebook” 人家拍拍屁股混了一圈, 说不干就不干! 因为觉得人生太无聊, 顺手破解了索尼的游戏机, 逼的索尼将他告上法庭, 还引发了世!界!级!黑客

程序员写 2000 行 if else?领导:这个锅我不背

前言 知乎上有小伙伴提了这么一个问题,如何看待陕西省普通话水平测试成绩查询系统?查询系统前端代码就直接给出了身份账号,姓名,证书编号,如果信息是真的,就泄露了这么多考生的信息,白给那种.为什么会发生这样的事情?事情的始末是什么? 证据 很多机智的小伙伴都打开了网址一探究竟,小编也不敢怠慢赶紧瞅瞅这牛逼的网站到底长什么样子. 看着的确有模有样,一股80年代的复古风格,赶紧拿出 F12 神器看一遍究竟哪位程序员写出如此神奇的逻辑代码. 点开层层结构,找到 <script>,卧槽还有这等神逻辑,本地

2000行之Qt简化写字板

//mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QLabel> namespace Ui { class MainWindow; } class QLineEdit; class QDialog; class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(Q

2000行之widget练习之二

//mydialog.h #ifndef MYDIALOG_H #define MYDIALOG_H #include <QDialog> namespace Ui { class MyDialog; } class MyDialog : public QDialog { Q_OBJECT public: explicit MyDialog(QWidget *parent = 0); ~MyDialog(); private slots: void on_pushButton_clicked(

2000行之句柄

#include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK); return 0; } #include <windows.h> const char g_

2000行之宏中#和##的区别

#include<stdio.h> #define Fun(a,b) a##b int main() { x='H'; y='W'; printf("%s",Fun(x,y)); return; } #include<stdio.h> #define Var(x) var##x int main() { int Var(1)=1,Var(2)=2,Var(3)=3; printf("var1=%d\n",var1); printf("

2000行之widget练习

//mywidget.h #ifndef MYWIDGET_H #define MYWIDGET_H #include <QWidget> #include <QWizard> namespace Ui { class MyWidget; } class MyWidget : public QWidget { Q_OBJECT public: explicit MyWidget(QWidget *parent = 0); ~MyWidget(); private slots: vo

2000行之Qt实现的简单登录界面

//mydialog.h #ifndef MYDIALOG_H #define MYDIALOG_H #include <QDialog> namespace Ui { class MyDialog; } class MyDialog : public QDialog { Q_OBJECT public: explicit MyDialog(QWidget *parent = 0); ~MyDialog(); private slots: void on_pushButton_clicked(

2000行之C++基础练习

#include<iostream> using namespace std; enum GameResult{WIN,LOSE,TIE,CANCEL}; int main(){ GameResult result; enum GameResult omit = CANCEL; for(int count = WIN;count <= CANCEL;count++){ result = GameResult(count); if(result = omit) cout<<&q