0% found this document useful (0 votes)
4 views2 pages

Exp 5prq1

Uploaded by

Naqiya Nullwala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Exp 5prq1

Uploaded by

Naqiya Nullwala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EXPERIMENT 5

PRACTICAL RELATED QUESTIONS:-

1) Write a program to find area of circle such that the class circle must have three functions namely:

Read,calculate and display.

#include<iostream>

using namespace std;

class circle { public:

int r;

float area;

void getdata() {

cout<<"Enter the radius"<<endl;

cin>>r; }

void calc_area() {

area=2*3.14*r; }

void putdata() {

cout<<"Area= "<<area<<endl; }};

int main(){

circle c;

cout<<"Name:-Naqiya Nullwala\nRollno.:-230433\n";

c.getdata();

c.calc_area();

c.putdata();

return 0; }
EXPERIMENT 5

PRACTICAL RELATED QUESTIONS:-

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>

using namespace std;

class Complex {

float real,imaginary;

public:

void read() {

cout << "Enter the real part: ";

cin >> real;

cout << "Enter the imaginary part: ";

cin >> imaginary; }

void write() {

cout << real << " + " << imaginary << "i" << endl; }

Complex add(Complex c) {

Complex temp;

temp.real = real + c.real;

temp.imaginary = imaginary + c.imaginary;

return temp; } };

int main() {

Complex c1, c2, c3;

cout<<"Naqiya Nullwala\n230433\n";

cout << "Enter the first complex number:\n";

c1.read();

cout << "Enter the second complex number:\n";

c2.read();

c3 = c1.add(c2);

cout << "The sum of the two complex numbers is: ";

c3.write(); return 0;

You might also like