车库 一个车库有 20 辆汽车待售。

车库 一个车库有 20 辆汽车待售。

一辆汽车参数如下:

     registration
     brand
     model ·power。
     year of commercialization
     price

编写程序:

1.获取 20 个车库汽车结构成员       √

2。查看汽车列表                               √

3.向用户询问品牌并显示该品牌的汽车列表               ×

4.计算车库汽车的平均价格                    √

5.确定最昂贵的汽车                       √

#include<stdio.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

class  Student{
	//创建对象 
	public:
	int price;
	int year;
	int pow;
	char* name ="car"; 
	void print(){
		cout<<name<<"的价格是"<<price<<",年份是"<<year<<",功率是"<<pow<<endl;
	}
};
int main(){

	
	Student stu;
	stu.price=100;
	stu.year=2001;
	stu.pow=100;
	stu.print();
	//for循环创建20个车对象
	Student arr[20] ;
	for(int i=0;i<20;i++){
		Student stui;
	stui.price=i*100;
	stui.year=2001;

	srand((unsigned)time(NULL));
	stui.pow=i*rand();
	stui.print();
	arr[i]=	stui;
	} 
	
	int total=0;
	int max=0; 
	for(int i=0;i<20;i++){
		//计算平均价格和总价格 
		total+=arr[i].price;
		if(arr[i].price>max){
			max=arr[i].price;
		}
	}
	int pjz= total/20;
	printf("总价格是:%d\n", total);
	printf("平均价格是:%d\n",pjz);
	printf("最大的价格是:%d\n",max);
	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值