C++课堂练习一

Posted liqing45

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++课堂练习一相关的知识,希望对你有一定的参考价值。

课程内容:https://www.icourse163.org/course/XJTU-46006

1、生日贺卡

#include<iostream>
#include<string>
using namespace std;

int main()
    char addressee[50], sender[50];
    cout << "请输入收信人:" << endl;
    cin.getline(addressee, 50);
    cout << "请输入寄信人:" << endl;
    cin.getline(sender, 50);
    cout << "#################################" << endl;
    cout << addressee << endl;
    cout << endl;
    cout << "Happy birthday to you!" << endl;
    cout << endl;
    cout << "    sincerely yours " << sender << endl;
    cout << "#################################" << endl;
    return  0;   

技术图片

2、加法计算器

#include<iostream>
using namespace std;
int main()
    int a, b;
    int c;
    cout << "计算a+b,请输入a,b:" << endl;
    cin >> a >> b;
    c = a + b;
    cout << "c = " << c << endl;
    return 0;

技术图片

3、计算本息和

#include<iostream>
#include<cmath>
using namespace std;
int main()

    double money, years, rate, sum;
    cout << "请输入本金,年份,利率:" << endl;
    cin >> money >> years >> rate;
    while (money >= 0) 
    
        sum = money * pow((1 + rate), years);
        cout << "本息和 = " << sum << endl;
        cout << "请输入本金,年份,利率(本金小于0时退出):" << endl;
        cin >> money >> years >> rate;
    
    return 0;

技术图片

以上是关于C++课堂练习一的主要内容,如果未能解决你的问题,请参考以下文章

课堂练习

01课堂练习

课堂练习

课堂练习 -- 找水王续

结对开发 课堂练习

课堂练习三