Ankush Mca-I (Sem Ii) 501
Ankush Mca-I (Sem Ii) 501
Ankush Mca-I (Sem Ii) 501
#include<iostream.h>
#include<conio.h>
struct ComplexNum
{
float x, y;
};
void main()
{
struct ComplexNum c1, c2, a, s, m, d;
PURCITM Page 1
Ankush MCA-I(Sem=II) 501
clrscr();
cout<<"Enter the First Number\n";
cout<<"Real Part = ";
cin>>c1.x;
cout<<"Imaginary Part = ";
cin>>c1.y;
cout<<"Enter the Second Number\n";
cout<<"Real Part = ";
cin>>c2.x;
cout<<"Imaginary Part = ";
cin>>c2.y;
cout<<"\nOperation on Two Complex Numbers :\n";
cout<<"\nAddition : ";
Add(c1,c2);
cout<<"\nSubtraction : ";
Sub(c1,c2);
cout<<"\nMultiplication : ";
Mul(c1,c2);
cout<<"\nDivision : ";
Div(c1,c2);
getch();
}
OUTPUT:
Addition : 15 + 12i
Subtraction : 9 + 8i
Multiplication : 16 + 54i
Division : 56 + 6i
PURCITM Page 2
Ankush MCA-I(Sem=II) 501
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void add();
void sub();
void mul();
void div();
void simplify(int n,int d);
struct Ratio
{
int numr,denr;
}rat1,rat2;
void main()
{
int opt;
while(1)
{
int flag=0;
clrscr();
cout<<"\tMake your selection to perform operations on ratios:\n\n";
cout<<"\t\t1. Addition\n";
cout<<"\t\t2. Subtraction\n";
cout<<"\t\t3. Multiplication\n";
cout<<"\t\t4. Division\n";
cout<<"\t\t5. Exit";
cin>>opt;
if(opt>=1 && opt<=4)
{
cout<<"\tEnter First ratio:\n\n";
cout<<"\t\tNumerator: ";
cin>>rat1.numr;
cout<<"\t\tDenominator: ";
cin>>rat1.denr;
cout<<"\n\n\n\n\tEnter Second ratio:\n\n";
cout<<"\t\tNumerator: ";
cin>>rat2.numr;
cout<<"\t\tDenominator: ";
cin>>rat2.denr;
}
PURCITM Page 3
Ankush MCA-I(Sem=II) 501
switch(opt)
{
case 1:
{
add();
break;
}
case 2:
{
sub();
break;
}
case 3:
{
mul();
break;
}
case 4:
{
div();
break;
}
case 5:
{
exit(0);
}
default:
{
cout<<"Wrong input";
getch();
exit(0);
}
}
getch();
}
void add()
{
rat1.numr=((rat1.numr*rat2.denr)+(rat2.numr*rat1.denr));
rat1.denr=(rat1.denr*rat2.denr);
cout<<"\n\n\tAddition of two Ratios:\n\t\t";
simplify(rat1.numr,rat1.denr);
PURCITM Page 4
Ankush MCA-I(Sem=II) 501
void sub()
{
rat1.numr=((rat1.numr*rat2.denr)-(rat2.numr*rat1.denr));
rat1.denr=(rat1.denr*rat2.denr);
cout<<"\n\n\tSubtraction of two Ratios:\n\t\t";
simplify(rat1.numr,rat1.denr);
}
void mul()
{
rat1.numr=(rat1.numr*rat2.numr);
rat1.denr=(rat1.denr*rat2.denr);
cout<<"\n\n\tMultiplication of two Ratios:\n\t\t";
simplify(rat1.numr,rat1.denr);
}
void div()
{
rat1.numr=(rat1.numr*rat2.denr);
rat1.denr=(rat1.denr*rat2.numr);
cout<<"\n\n\tDivision of two Ratios:\n\t\t";
simplify(rat1.numr,rat1.denr);
}
OUTPUT:
Make your selection to perform operations on ratios:
1. Addition
2. Subtraction
PURCITM Page 5
Ankush MCA-I(Sem=II) 501
3. Multiplication
4. Division
5. Exit3
Enter First ratio:
Numerator: 23
Denominator: 32
Numerator: 3
Denominator: 2
PURCITM Page 6
Ankush MCA-I(Sem=II) 501
/*WAP for creating structure DATE holding three values for day, month and
year. Write function for:
a) Check the given date is valid or not
b) Finding the difference in two dates
c) Display the date in format mm/dd/yyyy, Month dd, yyyy and dd-mm-yyyy
d) Detremine whether the given year is a leap year or not. */
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
struct DATE
{
int day, month, year;
}d;
PURCITM Page 7
Ankush MCA-I(Sem=II) 501
if(d.month%2 == 0)
{
if(d.day>30)
cout<<"You entered invalid date";
else
cout<<"You entered valid date";
}
else
cout<<"Date is valid";
}
else if(d.month > 7)
{
if(d.month%2 != 0)
{
if(d.day>30)
cout<<"You entered invalid date";
else
cout<<"You entered valid date";
}
else
cout<<"Date is valid";
}
}
}
PURCITM Page 8
Ankush MCA-I(Sem=II) 501
case 6:
y=151; break;
case 7:
y=181; break;
case 8:
y=212; break;
case 9:
y=243; break;
case 10:
y=273; break;
case 11:
y=304; break;
case 12:
y=334; break;
default:
cout<<"Error encountered";
exit(1);
}
return(y);
void diff(DATE d)
{
DATE d1, diff;
cout<<"\nEnter second values for DATE\nDay:\n";
cin>>d1.day;
cout<<"Month:\n";
cin>>d1.month;
cout<<"Year:\n";
cin>>d1.year;
int ref,dd1,dd2,i;
ref = d.year;
if(d1.year<d.year)
ref = d1.year;
dd1=0;
dd1=func1(d.month);
for(i=ref;i<d1.year;i++)
{
if(i%4==0)
PURCITM Page 9
Ankush MCA-I(Sem=II) 501
dd1+=1;
}
struct DATE temp;
if(d.year>d1.year)
{
temp = d;
d = d1;
d1 = temp;
}
dd1=dd1+d.day+(d.year-ref)*365;
cout<<"\nNo. of days of first date fronm the Jan 1 "<<d.year<<" = "<<dd1;
/* Count for additional days due to leap years*/
dd2=0;
for(i=ref;i<d1.year;i++)
{
if(i%4==0)
dd2+=1;
}
dd2=func1(d1.month)+dd2+d1.day+((d1.year-ref)*365);
cout<<"\nNo. of days from the reference year's first Jan = "<<dd2;
cout<<"\nTherefore, diff between the two dates is "<<abs(dd2-dd1);
getch();
}
void display(DATE d)
{
cout<<"Date in form of mm/dd/yyyy: "<<d.day<<"/"<<d.month<<"/"<<d.year;
cout<<"\nDate in form of month date,year: "<<d.day<<" "<<d.month<<","<<d.year;
cout<<"\nDate in form of dd-mm-yyyy: "<<d.month<<"-"<<d.day<<"-"<<d.year;
}
int leap(DATE d)
{
if(((d.year%4 == 0) && (d.year%100 != 0)) || (d.year%400 == 0))
{
cout<<"Year entered is a Leap year";
return 1;
}
else
PURCITM Page 10
Ankush MCA-I(Sem=II) 501
{
cout<<"Year entered is not a Leap Year";
return 0;
}
}
void main()
{
int val;
clrscr();
cout<<"Entering DATE\nEnter day:\n";
cin>>d.day;
cout<<"Entering month:\n";
cin>>d.month;
cout<<"Entering year:\n";
cin>>d.year;
cout<<"\nPerforming functions as:\n";
cout<<"Checking the given date is valid or not\n";
valid(d, val);
cout<<"\n\nFinding the difference in two dates\n";
diff(d);
cout<<"\n\nDisplay the date in format mm/dd/yyyy, Month dd, yyyy and dd-mm-
yyyy\n";
display(d);
cout<<"\n\nDetermine whether the given year is a leap year or not\n";
val = leap(d);
getch();
}
OUTPUT:
Entering DATE
Enter day:
12
Entering month:
4
Entering year:
2000
PURCITM Page 11
Ankush MCA-I(Sem=II) 501
Display the date in format mm/dd/yyyy, Month dd, yyyy and dd-mm-yyyy
Date in form of mm/dd/yyyy: 12/4/2000
Date in form of month date,year: 12 4,2000
Date in form of dd-mm-yyyy: 4-12-2000
PURCITM Page 12
Ankush MCA-I(Sem=II) 501
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int size = 0;
struct DATE
{
int date, month, year;
};
struct EMPLOYEE
{
int empCode;
char empName[25], dept[20], Rank[15];
float Salary;
struct DATE DOB, DOJ;
}Emp[20];
void insert(void)
{
cout<<"Insert a new record\n";
cout<<"Enter employee Code: ";
cin>>Emp[size].empCode;
cout<<"Enter employee Name: ";
cin>>Emp[size].empName;
cout<<"Enter employee Department ";
cin>>Emp[size].dept;
cout<<"Enter emplyee's DOB in form of dd mm yyyy ";
cin>>Emp[size].DOB.date;
cin>>Emp[size].DOB.month;
cin>>Emp[size].DOB.year;
cout<<"Enter emplyee's DOJ in form of dd mm yyyy ";
cin>>Emp[size].DOJ.date;
cin>>Emp[size].DOJ.month;
PURCITM Page 13
Ankush MCA-I(Sem=II) 501
cin>>Emp[size].DOJ.year;
cout<<"Enter employee's Rank ";
cin>>Emp[size].Rank;
cout<<"Enter emplyee's Salary ";
cin>>Emp[size].Salary;
size++;
}
PURCITM Page 14
Ankush MCA-I(Sem=II) 501
void display(void)
{
if(size == 0)
cout<<"There is nothing to display\n";
else
{
cout<<”\n”;
for(int i = 0; i<size; i++)
{
cout<<"Record of "<<i+1<<" :\n";
cout<<"Employee Code : "<<Emp[i].empCode;
cout<<"\nEmplyee Name : "<<Emp[i].empName;
cout<<"\nEmplyee Department : "<<Emp[i].dept;
cout<<"\nEmployee DOB : "<<Emp[i].DOB.date;
cout<<"-"<<Emp[i].DOB.month;
cout<<"-"<<Emp[i].DOB.year;
cout<<"\nEmployee DOJ : "<<Emp[i].DOJ.date;
cout<<"-"<<Emp[i].DOJ.month;
PURCITM Page 15
Ankush MCA-I(Sem=II) 501
cout<<"-"<<Emp[i].DOJ.year;
cout<<"\nEmplyee Rank : "<<Emp[i].Rank;
cout<<"\nEmplyee Salary : "<<Emp[i].Salary;
cout<<"\n\n";
}
}
}
void sort(void)
{
struct EMPLOYEE temp;
int check1, check2, check3, i, j = 0, k = 0, l = 0;
for(i = 0; i<size; i++)
{
for(j = 1; j<size; j++)
{
check1 = strcmp(Emp[i].dept, Emp[j].dept);
if(check1>0)
{
temp = Emp[i];
Emp[i] = Emp[j];
Emp[j] = temp;
}
}
}
for(i = 0; i<size;)
{
for(; j<size; j++)
{
check2 = strcmp(Emp[i].dept, Emp[j].dept);
if(check2 > 0)
break;
else
{
continue;
j++;
}
}
for(; l<j; l++)
{
PURCITM Page 16
Ankush MCA-I(Sem=II) 501
void main()
{
char chk = 'y';
int num, EmpCode;
clrscr();
while((chk == 'y') || (chk == 'Y'))
{
cout<<"\nMake your selection\n";
cout<<"Press 1 to enter new employee record\n";
cout<<"Press 2 to modify an existing record\n";
cout<<"Press 3 to delete an existing reord\n";
cout<<"Press 4 to display all the records\n";
cout<<"Press 5 to sort the records dept wise, then within a dept. rank wise\n";
cout<<"Press 6 to exit\n";
cin>>num;
if((num<1) || (num>6))
{
cout<<"\nYou made an invalid selection";
continue;
}
switch(num)
{
case 1:
insert();
break;
PURCITM Page 17
Ankush MCA-I(Sem=II) 501
case 2:
cout<<"Enter the Employee code you want to modify\n";
cin>>EmpCode;
modify(EmpCode);
break;
case 3:
cout<<"Enter the Employee code you want to delete\n";
cin>>EmpCode;
deletee(EmpCode);
break;
case 4:
display();
break;
case 5:
sort();
break;
case 6:
exit(0);
}
while(1)
{
fflush(stdin);
cout<<"\nDo you want to continue Y/N\n";
cin>>chk;
if((chk == 'Y') || (chk == 'y'))
break;
else if((chk == 'N') || (chk == 'n'))
exit(0);
else
{
cout<<"You made an invalid selection";
continue;
}
}
if((chk == 'Y') || (chk == 'y'))
continue;
}
getch();
}
PURCITM Page 18
Ankush MCA-I(Sem=II) 501
OUTPUT:
PURCITM Page 19
Ankush MCA-I(Sem=II) 501
Record of 1 :
Employee Code : 1
Emplyee Name : Varun
Emplyee Department : Comp.Sc.
PURCITM Page 20
Ankush MCA-I(Sem=II) 501
Record of 2 :
Employee Code : 2
Emplyee Name : Piyush
Emplyee Department : Admin
Employee DOB : 6-7-1987
Employee DOJ : 21-4-1999
Emplyee Rank : Client
Emplyee Salary : 20000
Record of 3 :
Employee Code : 3
Emplyee Name : Nakul
Emplyee Department : Admin
Employee DOB : 4-3-1987
Employee DOJ : 20-11-1998
Emplyee Rank : Administrator
Emplyee Salary : 40000
PURCITM Page 21
Ankush MCA-I(Sem=II) 501
Record of 1 :
Employee Code : 3
Emplyee Name : Nakul
Emplyee Department : Admin
Employee DOB : 4-3-1987
Employee DOJ : 20-11-1998
Emplyee Rank : Administrator
Emplyee Salary : 40000
Record of 2 :
Employee Code : 1
Emplyee Name : Varun
Emplyee Department : Comp.Sc.
Employee DOB : 21-3-1988
Employee DOJ : 11-1-2000
Emplyee Rank : HOD
Emplyee Salary : 35000
Record of 3 :
Employee Code : 2
Emplyee Name : Piyush
Emplyee Department : Admin
Employee DOB : 6-7-1987
Employee DOJ : 21-4-1999
Emplyee Rank : Client
Emplyee Salary : 20000
PURCITM Page 22