cs106x-lecture1(Autumn 2017)

开始打卡cs106x(Autumn 2017)-lecture1

cs106x这门课的介绍: 主要通过 C++ 语言让学生在实际的编程作业里培养通过编程抽象解决实际问题的能力,同时也会涉及一些简单的数据结构和算法的知识,但总体来说没有一门专门的数据结构课那么系统。

1、CodeStepByStep-helloWorld

Write a complete C++ program with a main function that prints the following console output:

Hello, world!

解答

#include <iostream>
#include "console.h"

using namespace std;

int main() {
    cout << "Hello, world!" << endl;
    return 0;
}

2、CodeStepByStep-stanfordVsCal

Write a complete C++ program with a main function that computes who won the Stanford-Berkeley football game. The program should ask the user for the two scores. You may assume that the user enters valid non-negative integers. Below is an example dialogue (user input is shown like this):

Stanford: How many points did they score? 87
Cal: How many points did they score? 3
Stanford won!

解答

#include <iostream>
#include "console.h"
#include "simpio.h"

using namespace std;

int main()
{
    int stanford = getInteger("Stanford: How many points did they score?");
    int cal = getInteger("Cal: How many points did they score?");

    if (stanford >= cal) {
        cout << "Stanford won!" << endl;
    } else {
        cout << "Cal won!" << endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值