C++ 生手求解

C++ 新手求解
本帖最后由 psp_66 于 2014-06-14 00:31:23 编辑
如何写一个下面的程序,把两个.exe放一个里面

*************************************************
 1:Hito.exe
 2:PointerSample.exe
Which ?
**********************

例如上面这个输入1执行Hito.exe  ,输入2执行Pointer .exe,输入exit或者其他数字结束。

补充下面两个是写好的单个程序

#include "Hito.h"

//Hito.cpp

// define include statment
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;
string name;
int yearsold;

//Define Class
class CHito
{
private:
    char m_name[40];
    int m_age;
public:
    void setname(char* ss)
    {
        strcpy(m_name,ss);
    }
    void setage(int tosi)
    {
        if(tosi<0) m_age=0; else m_age=tosi;
    }
    void disp()
    {
        cout << "name:" << m_name << endl;
        cout << "age:" << m_age << endl;
    }
    
};

void hitodispyamada()
{
CHito yamada;
    
yamada.setname("AA");
yamada.setage(30);
yamada.disp();
}

void hitodispyamamoto()
{
CHito yamamoto;
    
yamamoto.setname("BB");
yamamoto.setage(50);
yamamoto.disp();
}


//start here.
int main(void)
{
    
    hitodispyamada();
    hitodispyamamoto();
cout << endl;
return 0;
}



// PointerSample.cpp
#include <iostream>
using namespace std;

void AddressSample()
{
int x = 3;
cout << "x " << x << endl;
cout << " x " << &x << endl;
    
}void PointerSample()
{
int x = 4;
int* p;
p = &x;
    
cout << " x " << x << endl;
cout << " x " << p << endl;
}

void PointerSample3()
{
int x = 3,y = 4;
int* p1;
int* p2;
p1 = &x;
p2 = &y;
cout << " x " << p1 << endl;
cout << " p1  " << *p1 << endl;
cout << " x " << p2 << endl;
cout << " p2 " << *p2 << endl;
}

int main()
{
AddressSample();
PointerSample();
PointerSample3();
cout << endl;
return 0;
}

------解决方案--------------------

int main()
{
    string s;
    while (s != "2")
    {
        cout << endl;
        cout << "*************************************************\n"
        " 1:Hito\n"
        " 2:PointerSample\n"
        "Which ? ";
        cin >> s;
        
        if (s == "1")
        {
            run("./Hito");
        }
        else if (s == "2")
        {
            run("./Point");
        }
   
    }
    return 0;
}