Exp 5prq1
Exp 5prq1
1) Write a program to find area of circle such that the class circle must have three functions namely:
#include<iostream>
int r;
float area;
void getdata() {
cin>>r; }
void calc_area() {
area=2*3.14*r; }
void putdata() {
int main(){
circle c;
cout<<"Name:-Naqiya Nullwala\nRollno.:-230433\n";
c.getdata();
c.calc_area();
c.putdata();
return 0; }
EXPERIMENT 5
Define a class complex with data members real and imaginary, member function read() and write().
Write a program to perform the addition of two complex number and display the result.
#include<iostream>
class Complex {
float real,imaginary;
public:
void read() {
void write() {
cout << real << " + " << imaginary << "i" << endl; }
Complex add(Complex c) {
Complex temp;
return temp; } };
int main() {
cout<<"Naqiya Nullwala\n230433\n";
c1.read();
c2.read();
c3 = c1.add(c2);
cout << "The sum of the two complex numbers is: ";
c3.write(); return 0;