11363人加入学习
(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;
}

 

\

[展开全文]

*”用于声明指针(申请房间)/指针指向所储存的数据((不是几几进制数的数据)看房间里面的东西);

&”取变量地址符号,简称拿钥匙符号(想要哪个房间钥匙就  &哪个房间号);

[展开全文]

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

[展开全文]

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

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

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

两边为真即为真

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

[展开全文]

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;
}
 

[展开全文]

这个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;
}

[展开全文]

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;
}

[展开全文]

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

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

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

[展开全文]

打怪终止源码:

// 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;
}

[展开全文]

// 14-字符串使用.cpp: 定义控制台应用程序的入口点。
//

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

int main()
{
    string  l;
    getline(cin, l);
    cout << l << endl;
    return 0;
}

[展开全文]

字符要用‘  ’来表示

字符串要用“ ”来表示

endl=end line

ctrl+k  ctrl+c:注释

ctrl+k  ctrl+u:取消注释

[展开全文]
  1. 结构体可以将不同类型组合在一起形成一个新的类型,这个类型是对数据的整合,让代码更加简洁。               struct   名字{                                            成员类型        成员名                      成员类型        成员名                                                              }
[展开全文]

#include<iostream>

#include<string>

using namespace std;

struct POSITION{

float x;

floaty;

float x;

}

int main(){

float ememy1x;

float ememy1y;

float ememy1z;kposition emem1pos;

cout<<emem1pos.x=9

struct enemy{

int hp;

int attack;

position pos;

string nsme;

}

}

enemy  enemy1={"siki",100,50,{1,1,1}}

cout<<enemy1.pos.x<<endl;

[展开全文]

int a=324

int*pA;//‘*’指针

pA=&a;//‘&’取地址符,获取a的地址

[展开全文]

cout<<pA<<endl;

指针获取地址

cout<<*pA<<endl;

指针获取地址的内容

*pA=300;

通过指针修改内容

[展开全文]

void*p1=&str;

cout<<*((int*)p1)<<endl;

void*是指向空类型的指针,可以指向任意类型但是输出时需要强制转换成某一类型,否则电脑无法确定指针类型会报错。

 

[展开全文]

int a=100;

int b=200;

int* p1=&a;  指针的声明

int& r1=a;     引用的声明

指针和引用除了声明不同其他都一模一样

引用的内存地址无法修改,修改等于重新赋值。

[展开全文]

在C++编程语言中,函数和方法是同理的。

#include <iostream>

using namespace std;

 

int main(){

 cout <<"Hello Worid" << end1;

return 0;

}

// 单行注释

/* 多行注释

[展开全文]

授课教师

SiKi学院老师

课程特色

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