码迷,mamicode.com
首页 > 其他好文 > 详细

实验三

时间:2018-04-08 13:24:29      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:end   new   stream   iostream   rectangle   ios   float   std   cin   

#include<iostream>
using namespace std;

class Rectangle{
	public:
		void attribute(float newL,float newW);
		void area(); 
		
	private:
		int length,width;
}; 

void Rectangle::attribute(float newL,float newW){
	length=newL;
	width=newW;
}

void Rectangle::area(){
	int area;
	area=length*width;
	cout<<"面积是:"<<area<<endl;
}


int main()
{
	float a,b;
	cout<<"输入长:"<<endl;
	cin>>a;
	cout<<"输入宽:"<<endl;
	cin>>b;
	Rectangle hahaha;
	hahaha.attribute(a,b);
	hahaha.area();
	return 0;
}

 技术分享图片

#include<iostream>
using namespace std;
 
 class Complex{
 	public:
 		Complex(double a,double b);
 		Complex(double a);
 		void add(Complex &p);
 		void show();
 	private:
	 	double real,imaginary;
 };
 
 Complex::Complex(double a,double b){
 	real=a;
 	imaginary=b;
 }
 
 Complex::Complex(double a){
 	real=a;
 }
 
 void Complex::add(Complex &p){
 	real=real+p.real;
 	imaginary=imaginary+p.imaginary;
 }
 
 void Complex::show(){
 	cout<<real<<"+"<<imaginary<<"i"<<endl;
 }
 
 int main()
 {
 	Complex c1(3,5);
 	Complex c2(4.5);
 	c1.add(c2);
 	c1.show();
 	return 0;
 }

  技术分享图片

 

实验三

标签:end   new   stream   iostream   rectangle   ios   float   std   cin   

原文地址:https://www.cnblogs.com/a18851962010/p/8744252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!