C++学习起步

//

//  main.cpp

//  C++(1)

//

//  Created by mac on 15-2-15.

//  Copyright (c) 2015 xutao. All rights reserved.

//


#include <iostream>//作用是将文件iostream的内容包含到该命令所在的程序文件中,代替该命令行。iostream是输出流的意思。



//int main(int argc, const char * argv[]) {

//    // insert code here...

//    std::cout << "Hello, World!\n";

//    return 0;

//}

//c++标准库的类和函数是在命名空间中std中声明的,因此如果需要用到c++标准库中信息时,就需要using namespace std,表示要用到命名空间std中得内容

/*

 

 using namespace std;//使用空间命名std

 int main()

 {

 

// cout 是输出流对象

 <<是插入运算符,与cout配合使用,在本例中将运算符“”这里面的语句插入到输出的队列cout

 

cout<<"This My First C++ Programm";

return 0;


}

 */

/*

//a,b两个数的和

using namespace std;

int main()

{

    int a,b,sum;

    cin >>a>>b;

    sum=a+b;

    cout<<"a+b="<<sum<<endl;

    

    


}

*/


/*

//求两个数中得最大者

using namespace std;

int main()

{

    int x,y,m;

    cin>>x>>y;

    m=max(x,y);

    cout<<"max="<<m<<endl;


    return 0;

}


int max(int x,int y)

{


    int z;

    if (x>z) {

        z=x;

    }else{

    

        z=y;

    }



    return z;


}

*/


//包含类的C++程序

using namespace std;

class Student {

private:

    int num;

    int score;

    

public:

    

    void setData(){

        cin>>num;

        cin>>score;

    }

    

    void display(){

        cout<<"num="<<num<<endl;

        cout<<"score="<<score<<endl;

    }

};


Student stud1,stud2;


int main()

{

    stud1.setData();

    stud2.setData();

    stud1.display();

    stud2.display();




}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值