1133人加入学习
(5人评价)
C++编程系列 第一季编程基础

制作于2018年2月7日

价格 免费
课程还未发布,不允许加入和购买

#include <iostream>

using namespace std;
int Height();
bool TimeRoutine(struct timeStruct* timeRoutine);
float ClassAndGrade(int boyNumber, int girlNumber);


// 第二题使用的结构体
struct timeStruct {
    int day;
    int hour;
    int minute;
    int second;

};

int main()
{
    //// 第一题
    //int height = 0;
    //height = Height();
    //cout << "身高是:" << height << "cm." << endl;

/*********************************************************************************************************************************************************/

    // 第二题
    // 编写一个程序,让用户输入秒,然后把它转换成多少天,多少小时,多少分钟和多少秒显示出来

    //bool timeBool = false;
    //timeStruct timeStr;
    //timeStr.day = 0;
    //timeStr.hour = 0;
    //timeStr.minute = 0;
    //timeStr.second = 0;
    //timeBool = TimeRoutine(&timeStr);
    //if (true == timeBool)
    //{
    //    cout << "时间是:" << timeStr.day << "天," << timeStr.hour << "小时," << timeStr.minute << "分钟," << timeStr.second << "秒." << endl;
    //}
    //else
    //{
    //    cout << "ERROR!" << endl;
    //}

/*********************************************************************************************************************************************************/

    // 第三题
    // 要求用户输入一个班级的男生女生的数量,并输出女生的比例(百分比)

    //int boy = 0;
    //int girl = 0;
    //if (0 == boy || 0 == girl)
    //{
    //    cout << "输入男生的人数:";
    //    cin >> boy;
    //    cout << endl;
    //    cout << "输入女生的人数:";
    //    cin >> girl;
    //    cout << endl;
    //}

    //float number = ClassAndGrade(boy, girl);
    //cout << "比例是:" << number << "%" << endl;

 


    return 0;
}


// 第三题
float ClassAndGrade(int boyNumber, int girlNumber)
{
    int sum = 0;
    float girl = 0;
    sum = boyNumber + girlNumber;
    girl = ((float)girlNumber / (float)sum) * 100;
    if (0 == girl)
    {
        return 0;
    }
    return girl;

}

// 第二题
bool TimeRoutine(struct timeStruct *timeRoutine)
{
    long int secondNumber = 0;
    
    if (0 == secondNumber)
    {
        cout << "输入一个时间秒:";
        cin >> secondNumber;
    }
    
    timeRoutine->day = (int)(secondNumber / 60 / 60 / 24);
    timeRoutine->hour = (int)(secondNumber / 60 / 60 % 24);
    timeRoutine->minute = (int)(secondNumber / 60 % 60);
    timeRoutine->second = (int)(secondNumber % 60);
    
    if (0 == timeRoutine->day && 0 == timeRoutine->hour && 0 == timeRoutine->minute && 0 == timeRoutine->second)
    {
        return false;
    }
    else
    {
        return true;
    }


}

// 第一题
int Height()
{
    float heightM = 0;
    int heightCM = 0;

    cout << "输入身高:" << endl;
    cin >> heightM;
    cout << endl;
    heightCM = (int)(heightM * 100);
    //cout << "身高是:" << heightCM << "cm" << endl;
    return heightCM;


}

[展开全文]

1.    float height;
    cout << "哥们,你多高耶?" << endl;
    cin >> height;
    if (height <= 3)
    {
        cout << (height * 100) << "cm" << endl;
    }
    else
    {
        cout << height << endl;
    }

2.    double lSeconds;
    cout << "哥们,输入随便一个以秒为单位的数字,哥哥我分分钟给你算出来是多少天多少小时多少分钟?不信你输个试试" << endl;
    cin >> lSeconds;
    cout << "来了" << endl;
    cout << lSeconds / 60 << "    " << "分钟" << endl;
    cout << lSeconds / 3600 << "    " << "小时" << endl;
    cout << lSeconds / (3600 * 24) << "    " << "天" << endl;

3.    cout << "兄弟,你们班上有几个男的耶?" << endl;
    float Male;
    cin >> Male;
    cout << "几个女的咧?" << endl;
    float Female;
    cin >> Female;
    cout << "我靠,你们班的女生占比百分之" << short((Female / (Male + Female)) * 100) << ",你们有福了" << endl;

[展开全文]

1.让用户输入自己的身高米,然后把它转换成厘米。


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

int main()
{
	float m;
	float cm;
	cout << "请输入身高(米)" << endl;
	cin >> m;
	cm = m * 100;
	cout << "身高(厘米)为:" << cm<<endl;
	return 0;


}

2.让用户输出秒,将其转化为多少天,多少小时,多少分钟和多少秒。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	int s;
	float d, h, m;
	cout << "请输入秒数" << endl;
	cin >> s;
	m = s / 60; h = m / 60; d = h / 24;
	cout << "对应的天数:" << d << endl;
	cout << "对应的小时数:" << h << endl;
	cout << "对应的分钟数:" << m << endl;
	cin.get();
}

3.输入一个班级男生和女生的数量,求其女生所占百分比。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	float m,f,p;
	cout << "请输入男生人数"<<endl;
	cin >> m;
	cout << "请输入女生人数"<<endl;
	cin >> f;
	p = (f / (m + f))*100;
	cout << "女生比例为"<<p<<"%"<<endl;
	return 0;

}

 

[展开全文]

授课教师

加我的QQ问问题:804632564

课程特色

下载资料(1)
视频(58)