11368人加入学习
(31人评价)
【旧版】C++编程系列 预备季快速上手

旧版课程,制作完成于2017-12-18

价格 免费

键盘接收数字进行调用计算源码:

#include"stdafx.h"
#include<iostream>
using namespace std;
int a1(int arg1, int arg2)
{
    int s = arg1 + arg2;
    return s;

}

int main()
{
    int a; int b;
    cout << "请输入数字进行计算:" << endl;
    cin >> a;
    cin >> b;
    int s = a1(a, b);
    cout << "计算结果为" << s << endl;

}

 

用调用进行大小比较源码:

#include"stdafx.h"
#include<iostream>
using namespace std;

int max(int x, int y)   //调用将a,b两个值传送给x,y
{
    int z;
    if (x > y)
        z = x;
    else
        z = y;
    return z;    //将z的值传送回去
}
int main()
{
    int a; int b;
    cout << "请输入数字进行大小比较:" << endl;
    cin >> a;
    cin >> b;
    int z = max(a, b);
    cout << "最大数字为" << z << endl;
}

 

改进版本:

#include"stdafx.h"
#include<iostream>
using namespace std;

int max(int x, int y)   //接收a,b的值
{
    /*int z;
    if (x > y)
        z = x;
    else
        z = y;
    return z;*/    //将z的值传送回去

    return x > y ? x : y;
}
int main()
{
    int a; int b;
    cout << "请输入数字进行大小比较:" << endl;
    cin >> a;
    cin >> b;
    int z = max(a, b);  //将a,b的值传送给x,y
    cout << "最大数字为" << z << endl;
}

 

\

[展开全文]

打怪终止源码:

// 10-for循环.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
    int i = 0;
    for (; i < 10; i++)
    {
        cout << "产生怪物" << endl;

        if (i == 6)
            break;   //终止循环次数
    }
    cout << "本次游戏结束  共杀死" << i << "怪物" << endl;
    return 0;
}

 

 

奇偶数判断源码:

// 11-for循环寻找100以内的奇数.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
    int i = 0;
    for (; i <= 100; i++)
    {
        if (i % 2 != 0)
            cout << "奇数有" << i << endl;
        else
            cout << "偶数有" << i << endl;

    }

    return 0;
}

[展开全文]

// 09-while循环.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
    
    cout << "hello word!" << s << endl;
    return 0;
}

[展开全文]

while产生怪物源码:

// 09-while循环.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
    int s = 0;
    cout << "系统将自定义生产怪物" << endl;
    while (s < 10)
    {
        cout << "系统怪" << endl;
        s++;
    }
    cout << "本次系统共产生了怪物" << s << endl;
    return 0;
}

[展开全文]

这个switch语句最典型的一个案例就是成绩查询系统,源代码:

// 07-switch判断语句.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;


int main()
{
    int s;
    cout << "请输入你孩子的成绩:" << endl;
        cin >> s;
    switch (s)
    {
    case 0:
    case 10:
    case 20:
    case 30:
    case 40:
    case 50:
        cout << "你的孩子期末考试成绩没有合格请开学补考!" << endl;
        break;
    case 60:
        cout << "你的孩子期末考试成绩没有合格请开学补考!" << endl;
        break;
    case 70:
        cout << "你的孩子成绩良" << endl;
        break;
    case 80:
        cout << "你孩子的成绩中等!" << endl;
        break;
    case 90:
        cout << "你孩子的成绩优秀!" << endl;
        break;
    case 100:
        cout << "你孩子可以不用写作了!" << endl;
        break;
    default:
        cout << "不好意思家长,请重新输入!分值(0-100)" << endl;
        
    }

 

 

 

同时VIP简易查询系统也是典型

// 08-if语句与switch语句的不同.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{   
    int s;
    cout << "VIP玩家等级查询系统" << endl;
    cout << "请输入你在游戏中充值多了游戏币:" << endl;
    cin >> s;
    if (s >= 0 && s <= 100)
        
        cout << "尊敬的玩家你是VIP1用户 全场游戏道具购买可享受9.5折优惠" << endl;
    
    else if (s > 100 && s <= 500)
    
        cout << "尊敬的玩家你是VIP2用户 全场游戏道具购买可享受8.5折优惠" << endl;
        
    else if (s > 500 && s <= 15000)

        cout << "尊敬的玩家你是VIP3用户 全场游戏道具购买可享受7.5折优惠" << endl;
    else if (s > 1500 && s <= 5000)
    
        cout << "尊敬的玩家你是VIP4用户 全场游戏道具购买可享受7.5折优惠" << endl;
    
    else if (s > 10000)

        cout << "尊敬的玩家你是VIP5用户 全场游戏道具购买可享受6折优惠" << endl;
    
    else 
    cout << "尊敬的玩家你是普通玩家用户哟! 全场游戏道具购买不享受优惠" << endl;

    return 0;
}

[展开全文]

if语句可做判断使用比如在游戏中判断用户的等级

大家可做一下比较数字大小是If判断语句中最典型的一个案例。

源码:

// 06-if语句判断.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{   
    int max;  int a; int b;
    cout << "请输入数字进行比较大小\n";
    cin >> a;
    cout << "请在次输入数字\n";
    cin >> b;
    if (a > b)
    {
        max = a;
        cout << "最大的数字为" << max << endl;
        cout << "最小的数字为" << b << endl;
    }
    else
    {
        max = b;
        cout << "最大的数字为" << max << endl;
        cout << "最小的数字为" << a << endl;
    }
    return 0;
}
 

[展开全文]

在C++语言中逻辑运算中&&  ||  !  这三种特殊的逻辑运算 

&& 与运算为判断时候表达式两边为真即为真一边是假即为假

|| 或运算为判断时候表达式其中一边为假即为假

两边为真即为真

!取非运算为判断时候表达式取相反即可 比如逻辑真取非即为逻辑假 

[展开全文]

++a 与 a++的相同功能都是自增加1 但在有时进行布尔运算的时候要注意++a与a++的运算符顺序

[展开全文]

#include

<> 库文件

自己创建的用“”

.h文件是头文件

.cpp是源文件

[展开全文]

结构体就相当于一个新的类型

包含不同的基本类型和其他类型

struct Position{

float x;

float y;

float z;

string name;

};

struct Enemy()

{

string name;

 int hp;

 int attack;

Position position; 

}

int main()

{

//声明

Position enemy1 ;

//初始化

enemy1.x=90;

enmey1.y=10;

enemy1.z=50;

enemy2.string = “旺旺”;

 

//结构赋值

Enemy enemy2 ={"敌人",100,50,{1,1,1}};

 

cout << enemy1.x<<endl;

cout << enemy2.position.x<<endl;

//类名.

[展开全文]

char c =‘c';

islower(c) //输出是正数代表true 输出是0代表不是字符或者是负数

putchar(tolower(c));

====================

string  name;

cin >> name;

cout<< "你输入的名字:"<< name<<endl;

 //cin 通过 “空格” 来风格输入

//用getline接收一整行

 

 

[展开全文]

 “\n”"Tab" 在C++中必须用“包围上

 

[展开全文]
  • cin cout 后面接着<<"想要输入的字符串"<<
  • 字符串输出都需要加上<< " "<<包围

 

[展开全文]

\n

endl

两者等价

 

[展开全文]
张鹏宇 · 2018-01-14 · 09-变量 0

Ctrl+k Ctrl+c 注释多行 Ctrl+K Ctrl+u 取消注释

 

但是特么的没说endl的作用 健忘的SIKI

~

常量 就是写的那个数字

[展开全文]

授课教师

SiKi学院老师

课程特色

图文(1)
下载资料(2)
视频(40)