c++类,矩形面积计算

#include<iostream>
using namespace std;
class Rectanglecalculator
 {
 private:
 	float length;
	float width;
 public:
    void setlength(float length)
    {	
 		this->length=length;//赋值地址 
	}	
 	void setwidth(float width)
 	{
 		this->width=width;
	 }
   
float rectangleCalculator()
 {
 	
 	return length*width;
 	 
  }	 
	double display()
	{
		 return  rectangleCalculator();//函数前加参数类型的可以不在括
		 //内写参数类型和参数,但必须写return 
		 //void必须写参数类型和参数,可以不写return
	 } 
	 
 };
 int main()
  {
  	Rectanglecalculator prt1;
  	prt1.setlength(12.3);
  	prt1.setwidth(2.3);
  	cout<<prt1.display();
  	return 0;
	   }
  

相关推荐

  1. c++矩形面积计算

    2024-03-30 12:20:02       40 阅读
  2. 利用C++面向对象范式编程求矩形面积

    2024-03-30 12:20:02       57 阅读
  3. 计算矩阵边缘元素之和(c++)

    2024-03-30 12:20:02       57 阅读
  4. C#Stopwatch高精度计时功能

    2024-03-30 12:20:02       52 阅读
  5. C++(4) 面向对象&、权限修饰符

    2024-03-30 12:20:02       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-30 12:20:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-30 12:20:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-30 12:20:02       87 阅读
  4. Python语言-面向对象

    2024-03-30 12:20:02       96 阅读

热门阅读

  1. 新能源汽车消费者购车习惯调查方案

    2024-03-30 12:20:02       41 阅读
  2. pytorch | transforms.Compose()函数

    2024-03-30 12:20:02       43 阅读
  3. Shell脚本基础 以及 变量和引用

    2024-03-30 12:20:02       38 阅读
  4. 数据按日期周期的分组聚合

    2024-03-30 12:20:02       41 阅读