C++实验报告
实验二
一.实验目的
熟悉对类的使用
二.实验要求:
1. 自己编写一个简单的 C++类程序
2. 类的要求:(1)一个 C++的复数类,类名为 complex,类中有两个私有成员变量 i.j.还有
一个成员函数 Show 用于显示数据。(2)编写一个 add 函数,实现两个复数相加。(3)
main 函数如下:
int main()
{
complex a1(10,20);
a1.show();
cout<<"-----------------"<<endl;
complex a2(30);
a2.show();
cout<<"-----------------"<<endl;
complex a3;
a3.show();
cout<<"-----------------"<<endl;
a3=add(a1,a2);
a3.show();
cout<<"-----------------"<<endl;
}
要求得到的输出结果为:
(i,j)=(10,20)
-----------------
(i,j)=(30,0)
-----------------
(i,j)=(0,0)
-----------------
(i,j)=(40,20)
三.实验内容
#include"iostream.h"
class complex
{
- 1
- 2
前往页