虚幻Unreal - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(86评价)
价格: 3079.00元

float Harmean(float a, float b);

int main()
{
    float x = 1.f, y = 1.f, harm;
    while (x != 0 && y != 0)
    {
        cout << "enter two number,first:";
        cin >> x;
        cout << "enter two number,second:";
        cin >> y;
        harm = Harmean(x, y);
        if (x != 0 && y != 0)
            cout << x << "和" << y << "的调和平均数为" << harm << endl;
    };
}

float Harmean(float a, float b)
{
    float har = (2 * a * b) / (a + b);
    return har;
}

[展开全文]
Haleeco · 2021-04-26 · 0

struct GameScore
{
    string name;
    float score;

};

int main()
{
    array<GameScore, 5> GameArr;
    for (int i = 0; i < 5; i++)
    {
        cout << "please enter a game name of you favorite:";
        cin >> GameArr[i].name;
        cout << "what is your rating of the game(0-10):";
        cin >> GameArr[i].score;
    }
    for (int i = 0; i < GameArr.size(); i++)
    {
        for (int j = i + 1; j < GameArr.size(); j++)
        {
            if (GameArr[i].score < GameArr[j].score)
            {
                GameScore temp;
                temp = GameArr[i];
                GameArr[i] = GameArr[j];
                GameArr[j] = temp;
            }
        }        
    }
    for (auto i: GameArr)
    {
        cout << i.name << "-" << i.score << endl;
    }
}
 

[展开全文]
Haleeco · 2021-04-24 · 0

静态变量-只初始化一次

[展开全文]
maryzhangyatong · 2021-04-04 · 0

药品物资管理

要求:

1.创建药品类来完成习题四中对药品相关的管理。

2.利用对象数组来完成对不同种类药品信息的存储。

3.使用this*指针。

4.使用作用域为类的常量。

Medicines.h

#pragma once
#pragma once
#define MEDICINES_H_
#include "string"
using namespace std;
enum kind { hp, mp };

class Medicines
{
private:
	string name_;
	kind kin_;
	int number_;
	float buy_;
	float sell_;
	static const int Price = 100;
public:
	Medicines(string name, kind kin, int number);
	float Buyin(Medicines& m, float res);
	float Sellout(Medicines& m, float res);
	void display(Medicines m);
	void show(kind k);
};

Medicines.cpp

#include "Medicines.h"
#include <iostream>
#include "stdio.h"
#include "string"
Medicines::Medicines(string name, kind kin, int number)
{
	name_ = name;
	kin_ = kin;
	number_ = number;
	buy_ = Price;
	sell_ = Price * (3.0 / 4);
}

float Medicines::Buyin(Medicines& m, float res)
{
	int i;
	int j = res;
	cout << "请输入购买数量:";
	cin >> i;
	if (j > i * this->buy_)
	{
		this->number_ += i;
		j -= i * this->buy_;
		cout << "购买了" << i << "瓶";
		show(this->kin_);
		cout << "药水" << endl;
	}
	else
		cout << "金钱不足" << endl;
	return j;
}

float Medicines::Sellout(Medicines& m, float res)
{
	int i;
	int j = res;
	cout << "请输入卖出数量:";
	cin >> i;
	if (i < this->number_)
	{
		this->number_ -= i;
		j += i * this->sell_;
		cout << "卖出了" << i << "瓶";
		show(this->kin_);
		cout << "药水" << endl;
	}
	else
		cout << "数量不足" << endl;
	return j;
}

void Medicines::display(Medicines m)
{
	cout << "名称:" << m.name_ << "  " << "种类:";
	show(m.kin_);
	cout << "  " << "数量:" << m.number_ << "  " << "购买价格" << m.buy_ << "  " << "出售价格" << m.sell_ << endl;

}

void Medicines::show(kind k)
{
	if (k == 0)
		cout << "hp ";
	else
		cout << "mp ";
}

主程序

#include <iostream>
#include "stdio.h"
#include "string"
#include "Medicines.h"
using namespace std;
int main()
{
	int select;
	float res = 1000;
	Medicines ms[2] = { { "hp药水",kind(0),5} ,{ "mp药水",kind(1),5} };
	do {
		cout << "请输入对应指令" << endl << "1.购买hp药 2.卖出hp药 3.购买mp药 4.卖出mp药 5.显示背包 6.退出" << endl;
		cin >> select;
		switch (select)
		{
		case 1:
			res = ms[0].Buyin(ms[0],res);
			break;
		case 2:
			res = ms[0].Sellout(ms[0], res);
			break;
		case 3:
			res = ms[1].Buyin(ms[1], res);
			break;
		case 4:
			res = ms[1].Sellout(ms[1], res);
			break;
		case 5:
		{
			ms[0].display(ms[0]);
			ms[1].display(ms[1]);
			cout << "剩余金钱为:" << res << endl;
		}
		break;
		case 6:
			break;
		default:
			break;
		}
	} while (select != 6);


}

 

[展开全文]
史小墙 · 2020-06-12 · 0

完成程序:药品物资管理

要求:1.利用结构体来存储目前用用的药物的名称,种类,数量,买入价格,卖出价格。

2.利用枚举来设置药物的种类(回复mp和回复hp)。

3.编写函数来控制药物的买入和卖出,卖出价格为买入价格的3/4。

4.编写函数来显示拥有的药物和剩余钱数。

5.通过输入数字来控制函数调用。

6.实现分离式编译。

头文件game.h

#pragma once
#ifndef GAME_H_
#define GAME_H_
#include "string"
using namespace std;
enum kind {hp,mp};
struct Bag
{
	string name;
	kind kin;
	int number;
	float buy;
	float sell;
};
int Buyin(Bag &b1,float res);
int Sellout(Bag &b1,float res);
void Display(Bag b1,int i);


#endif // !GAME_H_



game.cpp

#include <iostream>
#include "stdio.h"
#include "string"
#include "game.h"
int Buyin(Bag &b1, float res)
{
	float i = res;
	if (i < b1.buy)
	{
		cout << "金钱不足" << endl;
	}
	else
	{
		b1.number += 1;
		i -= b1.buy;
		cout << "购买一瓶药" << endl;
	}
	return i;
}
int Sellout(Bag &b1, float res)
{
	int i = res;
	if (b1.number< 0)
	{
		cout << "数量不足" << endl;
	}
	else
	{
		b1.number -= 1;
		i+= b1.sell;
		cout << "卖出一瓶药" << endl;
	}
	return i;
}
void Display(Bag b1,int i)
{
	if(i==0)
	cout << "名称:" << b1.name << "  " << "种类:" << "hp" << "  " << "数量:" << b1.number << "  " << "购买价格" << b1.buy << "  " << "出售价格" << b1.sell<<endl;
	else
	cout << "名称:" << b1.name << "  " << "种类:" << "mp" << "  " << "数量:" << b1.number << "  " << "购买价格" << b1.buy << "  " << "出售价格" << b1.sell << endl;

}

主文件

#include <iostream>
#include "stdio.h"
#include "string"
#include "game.h"
using namespace std;
int main()
{
	int select;
	float res = 1000;
	Bag bagh{ "hp药水",kind(0),5,100,75 };
	Bag bagm{ "mp药水",kind(1),5,100,75 };
	do {
		cout << "请输入对应指令" << endl << "1.购买hp药 2.卖出hp药 3.购买mp药 4.卖出mp药 5.显示背包 6.退出" << endl;
		cin >> select;
		switch (select)
		{
		case 1:
			res=Buyin(bagh, res);
			break;
		case 2:
			res = Sellout(bagh, res);
			break;
		case 3:
			res = Buyin(bagh, res);
			break;
		case 4:
			res = Sellout(bagm, res);
			break;
		case 5:
		{
			Display(bagh, bagh.kin);
			Display(bagm, bagm.kin);
			cout << "剩余金钱为:" << res << endl;
		}
		break;
		case 6:
			break;
		default:
			break;
		}
	}
	while (select != 6);


}

 

[展开全文]
史小墙 · 2020-06-11 · 0

完成程序:设计分数显示

要求:

1.要求用户输入最多是个涉及分数,并且将他们存储在一个数组中。

2.输入负数提前完成输入。

3.使用三个数组处理函数分别进行输入,显示和计算平均分数的操作。


#include <iostream>
#include "stdio.h"
#include "string"
using namespace std;
void print(int arr[], int size);
int Sr(int arr[], int size=10);
void pj(int arr[], int size);

int main()
{
	int arr[10];
	int size= Sr(arr);
	print(arr, size);
	pj(arr, size);
}
int Sr(int arr[], int size)
{
	int i = 0;
	cout << "请输入10次的成绩" << endl;
	while (cin >> arr[i] && arr[i] >= 0)
	{
		i++;
		if (i == 10)
			break;
	}
	return i;
}
void print(int arr[], int size)
{
	for (int i = 0; i <size; i++)
	{
		cout << "第" << i+1 << "次成绩为" << arr[i] << endl;
	}
}
void pj(int arr[],int size)
{
	float sum = 0;
	for (int i = 0; i < size; i++)
	{
		sum += arr[i];
	}
	cout << "成绩平均值为" << sum / size << endl;


}

 

[展开全文]
史小墙 · 2020-06-09 · 0

习题改

#include <iostream>
#include "stdio.h"
#include "string"
using namespace std;
float pj(float i, float j);
int main()
{
	float a, b, temp;
	cout << "请输入两个数的值" << endl;
	while (cin >> a >> b && a != 0 && b != 0)
	{

		cout << a << "和" << b << "的" << "调和平均数为" << pj(a, b) << endl;
		cout << "请输入两个数的值" << endl;

	}

}
float pj(float i, float j)
{
	float sum = 1 / ((1 / i + 1 / j) / 2);
	return sum;
}

 

[展开全文]
史小墙 · 2020-06-09 · 0

练习:求两个数的调和平均数

要求:

1.不断要求用户输入两个数,知道其中一个数的值为0;

2.对于每两个数,程序将使用一个函数来计算他们的调和平均数。

3.函数将计算结果放会给主函数,在主函数中输出输出输入的数字和他们的调和平均数。

4.调和平均数是指倒数平均值的倒数。

#include <iostream>
#include "stdio.h"
#include "string"
using namespace std;
float pj(float i, float j);
int main()
{
	float a, b, temp;
	do
	{
		cout << "	请输入a的值" << endl;
		cin >> a;
		cout << "	请输入b的值" << endl;
		cin >> b;
		temp = pj(a, b);
		cout << "a= " << a << endl << "b= " << b << endl << "调和平均值= " << temp << endl;
	} while (a != 0 && b != 0);
}
float pj(float i, float j)
{
	float sum = 1 / ((1 / i + 1 / j)/2);
	return sum;
}

 

[展开全文]
史小墙 · 2020-06-09 · 0

static int  直到程序终止才结束

[展开全文]
wazc_5558 · 2019-06-17 · 0

constexp可以在编译时计算其返回值

[展开全文]
楚轩DX · 2019-04-26 · 0

long fact(int i)

{

long temp;

if (i==0)

{

temp=1;

}

else

{

temp=1*fact(i-1);

}

return temp;

}

[展开全文]
楚轩DX · 2019-04-20 · 0

再看一遍

[展开全文]
楚轩DX · 2019-04-15 · 0

void 没有返回值的函数

[展开全文]
楚轩DX · 2019-04-12 · 0

if 语句:

if (num1>mun2)

{

cout<<num1<<"和"<<mun2<<"j较大的值为:"<<num1<<endl;

}

else if(num1<num2)

{

cout<<num1<<"和"<<num2<<"中较大的值为:"<<num2<<endl;

}

else

{

cout<<num1<<"和"<<num2<<"相等"<<endl;

}

(else if 可以有多个,if 和 else 只能有一个)

 

switch 语句:

switch (stu1.gender)

{

case Male:

   cout<<stu1.name<<"是男生"<<endl;

   break;

case Female:

   cout<<stu1.name<<"是女生"<<endl;

   break;

default:

   break

}

 

for 循环:

for(int i=0;i<5;i++)

{

cout<<arr1[i]<<"";

}

cout<<endl;

 

while循环:

while(num1>=num2)

{

num1-=2;//减等于,每次减2

cout<<num1<<"";

}

cout <<endl;

[展开全文]
楚轩DX · 2019-04-12 · 0

算术运算符:

+,-,*,/,%(加,减,乘,除,求余)

关系运算符:

<,>,==,<=>=,!=

逻辑运算符:

&&(与,两边都为真才为真)

||(或,一边为真就为真,两边都为假就为假)

(非,非真即为假,非假即为真)

条件运算符:

int max=num1>num2 ? num1:num2;

(num1和num2中较大的值为哪一个)

int max=num1<num2 ? num1:num2;

(num1和num2中较小的值为哪一个)

[展开全文]
楚轩DX · 2019-04-12 · 0

数组:

int (int arr1[5]={1,2,3,4,5};)

float (float arr2[3]{1.2})

字符串:

string

结构体:

struct (struct Student) 结构体首字母要大写

枚举类型:

enum

指针:

int*pi=&score

[展开全文]
楚轩DX · 2019-04-12 · 0

整形:

int/ short/long

浮点型:

float/double

布尔型:

bool

字符类型:

char (char c='a')

ASCII表(每一个字符对应一个数字)

[展开全文]
楚轩DX · 2019-04-12 · 0

划重点

 

[展开全文]
lsw5530 · 2019-04-06 · 0

好晕啊

[展开全文]
GR90 · 2018-04-23 · 0

完全蒙了

[展开全文]
GR90 · 2018-04-23 · 0