0% found this document useful (0 votes)
41 views

Operating System Notes

The document defines a Complex structure with real and imaginary decimal members to store complex number components. It provides functions to add and multiply two complex numbers, returning the sum or product. The program uses a menu to accept user input for performing addition or multiplication on two complex numbers, displaying the result and continuing until an exit option is chosen. The document also defines a Student structure containing roll number, name, and marks in 3 subjects. It provides functions to create an array of Student structures by user input, and print details of students who failed more than one subject. The program demonstrates using these functions to accept student data and display failing students.

Uploaded by

ironman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Operating System Notes

The document defines a Complex structure with real and imaginary decimal members to store complex number components. It provides functions to add and multiply two complex numbers, returning the sum or product. The program uses a menu to accept user input for performing addition or multiplication on two complex numbers, displaying the result and continuing until an exit option is chosen. The document also defines a Student structure containing roll number, name, and marks in 3 subjects. It provides functions to create an array of Student structures by user input, and print details of students who failed more than one subject. The program demonstrates using these functions to accept student data and display failing students.

Uploaded by

ironman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

21) Define a structure Complex with two decimal data members a and b to store real

and imaginary part of a Complex number. Write the following functions :

void Add(Complex C1, Complex C2) // to add 2 complex numbers C1 and C2 and
display their sum

Complex Multiply(Complex C1, Complex C2) // to multiply 2 complex numbers C1 and


C2 and return their product.

Write a menu driven Program to accept 2 perform addition or multiplication of 2 complex


numbers depending on their option. The result should be displayed in the form of a
complex number.

The program should continue until the user chooses exit option. Display an appropriate
error message for any other option.

Hint :

(a+bi)+(c+di) = (a+c) + (b+d)i


(a+bi)*(c+di) = (ac−bd) + (ad+bc)i.

#include<iostream.h>
#include<conio.h>
struct Complex
{
float a,b;
};
void Add(Complex C1, Complex C2)
{
Complex C3;
C3.a=C1.a+C2.a;
C3.b=C1.b+C2.b;
cout<<"\nSum = "<<C3.a<<" + i"<<C3.b<<endl;
}
Complex Multiply(Complex C1, Complex C2)
{
Complex C3;
C3.a=C1.a*C2.a-(C1.b*C2.b);
C3.b=C1.a*C2.b+C2.a*C1.b;
return C3;
}
void main()
{
Complex P,Q,R;
int ch;
do
{
cout<<"1.Adding 2 Complex Numbers\n2.Multiplying 2 Complex Numbers\n3.Exit\n";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:cout<<"Enter real and imaginary part of 2 complex numbers";
cin>>P.a>>P.b>>Q.a>>Q.b;
Add(P,Q);
break;
case 2:cout<<"Enter real and imaginary part of 2 complex numbers";
cin>>P.a>>P.b>>Q.a>>Q.b;
R=Multiply(P,Q);
cout<<R.a<<" +i"<<R.b<<endl;
break;
case 3:break;
default:cout<<"Wrong choice...\n";
}
}while(ch!=3);
getch();
}
22) Create a structure STUDENT which contains rollno of int type, name of string
type and marks in three subjects of real type. Write a program which uses the
following functions, the prototypes which are given below:
i)void CREATE(STUDENT[], int N);// to create an array of N STUDENTS and
ii)void PRINT(STUDENT[], int N);// to print out the details of those students who have
failed in more than one subject.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct student
{
int rno;
char name[25];
float mk[3];
}s[10];
void create(student s[],int n)
{
for(int i=0;i<n;++i)
{
cout<<"Enter rno and name:";
cin>>s[i].rno;
gets(s[i].name);
cout<<"Enter marks in 3 subjects:";
for(int j=0;j<3;++j)
cin>>s[i].mk[j];
}
}

void print(student s[],int n)


{
int cnt=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<3;++j)
{
if(s[i].mk[j]<40)
cnt++;
}
if(cnt>1)
{
cout<<"\nStudent(s) failed in more than 1 subject:\n";
cout<<s[i].name<<"\t"<<s[i].mk[0]<<"\t"<<s[i].mk[1]<<"\t"<<s[i].mk[2];
}
}
}
void main()
{
clrscr();
int nos;
cout<<"\nEnter no.of students:";
cin>>nos;
create(s,nos);
print(s,nos);
getch();
}

You might also like