Operating System Notes
Operating System Notes
void Add(Complex C1, Complex C2) // to add 2 complex numbers C1 and C2 and
display their sum
The program should continue until the user chooses exit option. Display an appropriate
error message for any other option.
Hint :
#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];
}
}