Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective: You will get hands on experience of using Ø Loops Ø ConditionalStatem

ID: 3612116 • Letter: O

Question

Objective:

You will get hands on experience of using

Ø      Loops

Ø      ConditionalStatements

Ø      Message Boxes

Ø      Dialog Boxes

Ø      Event Handler

Ø      ActiveX controls (Textbox and Combo box)

Ø      Function calls

Ø      Menus

Ø      Threads

Develop a Thread based window calculator to perform thefollowing mathematical operation:

ü     Sin(x)                5 Marks

ü     Cos(x)               5 Marks

ü     Tan(x)               5 Marks

TIP:

User should specify the inputs and the operations to beperformed in sequence e.g if user presses the following sequence ofbuttons

Sin (1), Cos (3) and Tan (4) then user presses “equalto” button.

Explanation / Answer

Hi.. #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <math.h> void main() { clrscr(); char choice, choice2; int addition=0, sum=0, subtraction=0, sub=0,multiplication=1, multi=1, division=1,      dvs=1, square=0; double sinx, resultsin, cosx, resultcos, tanx,resulttan,; printf(" WINDOWS CALCULATOR n"); printf("Press enter to use the <A class="st_taginternal_tag" title="Posts tagged with   Calculator"href="… /tag/calculator/"rel=tag>calculator</A>");    getche(); clrscr(); printf("Enter choice n"); printf("Press n"); printf("[1] for Addition n"); printf("[2] for Subtraction n"); printf("[3] for Multiplication n"); printf("[4] for Division n"); printf("[5] for Scientific Functions n"); printf("[E] for Exit n"); choice=getch();    if((choice=='e')||(choice=='E')) exit(0); else if(choice=='1') { clrscr(); printf("Add numbers or press q to quit n"); do {    printf("Enter number ");    scanf("%d",&addition);    sum=addition+sum;
}    while(getch()!='q');    printf("Result is %d",sum);    getche(); } else if(choice=='2') { clrscr(); printf("---------------"); printf("Enter number "); scanf("%d",&subtraction); sub=subtraction; while(getch()!='q')
{    printf("Enter number ");    scanf("%d",&subtraction);    sub=sub-subtraction;
}    while(getch()!='q');    printf("Result is %d",sub);    getch(); } else if(choice=='3') { clrscr();    printf("Multiply numbers or press q to quit");    do    {     printf("Enter number ");    scanf("%d",&multiplication);     multi=multiplication*multi;
   }    while(getch()!='q'); printf("Result is %d",multi);    getch(); } else if(choice=='4') {     clrscr();    printf("                    ");     printf("Enter number ");   scanf("%d",&division);    dvs=division;     while(getch()!='q')    {      printf("Enter number");      scanf("%d",&division);      dvs=subtraction/dvs;}      printf("Result is%d",dvs);    getch();    }    else if(choice=='5')    {      clrscr();      printf(" Scientific Functionn");      printf("Press n");      printf("[6] for Sin xn");      printf("[7] for Cos xn");      printf("[8] for Tan xn");      printf("[E] for Exit n");      choice2=getch(); }    if((choice2=='e')||(choice2=='E'))    exit(0);    else if(choice2=='6') {    clrscr(); printf("This program calculate Sinx n");    printf("Enter number ");    scanf("%lf",&sinx);    resultsin=sin(sinx);    printf("The sin of %lf is %lfn", sinx,resultsin);    getche(); } else if(choice2=='7') {    clrscr();
   Printf("This program calculate Cos x n");    printf("Enter number ");    scanf("%lf",&cosx);    resultcos=cos(cosx);    printf("The Cos of %lf is %lfn", cosx,resultcos); } else if(choice2=='8') { clrscr(); printf("This program calculate Tan x n"); printf("Enter number ");
scanf("%lf",&tanx); resulttan=tan(tanx); printf("The Tan of %lf is %lfn", cosx,resultcos); } } #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <math.h> void main() { clrscr(); char choice, choice2; int addition=0, sum=0, subtraction=0, sub=0,multiplication=1, multi=1, division=1,      dvs=1, square=0; double sinx, resultsin, cosx, resultcos, tanx,resulttan,; printf(" WINDOWS CALCULATOR n"); printf("Press enter to use the <A class="st_taginternal_tag" title="Posts tagged with   Calculator"href="… /tag/calculator/"rel=tag>calculator</A>");    getche(); clrscr(); printf("Enter choice n"); printf("Press n"); printf("[1] for Addition n"); printf("[2] for Subtraction n"); printf("[3] for Multiplication n"); printf("[4] for Division n"); printf("[5] for Scientific Functions n"); printf("[E] for Exit n"); choice=getch();    if((choice=='e')||(choice=='E')) choice=getch();    if((choice=='e')||(choice=='E')) exit(0); else if(choice=='1') else if(choice=='1') { { clrscr(); clrscr(); printf("Add numbers or press q to quit n"); printf("Add numbers or press q to quit n"); do do { {    printf("Enter number ");    printf("Enter number ");    scanf("%d",&addition);    scanf("%d",&addition);    sum=addition+sum;
}    sum=addition+sum;
}    while(getch()!='q');    printf("Result is %d",sum);    printf("Result is %d",sum);    getche();    getche(); } } else if(choice=='2') else if(choice=='2') { { clrscr(); printf("---------------"); printf("---------------"); printf("Enter number "); printf("Enter number "); scanf("%d",&subtraction); scanf("%d",&subtraction); sub=subtraction; sub=subtraction; while(getch()!='q')
{ while(getch()!='q')
{    printf("Enter number ");    scanf("%d",&subtraction);    scanf("%d",&subtraction);    sub=sub-subtraction;
}    sub=sub-subtraction;
}    while(getch()!='q');    printf("Result is %d",sub);    printf("Result is %d",sub);    getch();    getch(); } else if(choice=='3') else if(choice=='3') { { clrscr(); clrscr();    printf("Multiply numbers or press q to quit");    printf("Multiply numbers or press q to quit");    do    do    {    {     printf("Enter number ");     printf("Enter number ");    scanf("%d",&multiplication);    scanf("%d",&multiplication);     multi=multiplication*multi;
   }     multi=multiplication*multi;
   }    while(getch()!='q'); printf("Result is %d",multi); printf("Result is %d",multi);    getch();    getch(); } } else if(choice=='4') else if(choice=='4') { {     clrscr();     clrscr();    printf("                    ");    printf("                    ");     printf("Enter number ");     printf("Enter number ");   scanf("%d",&division);   scanf("%d",&division);    dvs=division;    dvs=division;     while(getch()!='q')     while(getch()!='q')    {    {      printf("Enter number");      printf("Enter number");      scanf("%d",&division);      scanf("%d",&division);      dvs=subtraction/dvs;}      dvs=subtraction/dvs;}      printf("Result is%d",dvs);      printf("Result is%d",dvs);    getch();    getch();    }    }    else if(choice=='5')    else if(choice=='5')    {    {      clrscr();      clrscr();      printf(" Scientific Functionn");      printf(" Scientific Functionn");      printf("Press n");      printf("Press n");      printf("[6] for Sin xn");      printf("[6] for Sin xn");      printf("[7] for Cos xn");      printf("[7] for Cos xn");      printf("[8] for Tan xn");      printf("[8] for Tan xn");      printf("[E] for Exit n");      printf("[E] for Exit n");      choice2=getch();      choice2=getch(); } }    if((choice2=='e')||(choice2=='E'))    if((choice2=='e')||(choice2=='E'))    exit(0);    exit(0);    else if(choice2=='6')    else if(choice2=='6') {    clrscr(); printf("This program calculate Sinx n");    clrscr(); printf("This program calculate Sinx n");    printf("Enter number ");    printf("Enter number ");    scanf("%lf",&sinx);    scanf("%lf",&sinx);    resultsin=sin(sinx);    resultsin=sin(sinx);    printf("The sin of %lf is %lfn", sinx,resultsin);    printf("The sin of %lf is %lfn", sinx,resultsin);    getche();    getche(); } } else if(choice2=='7') else if(choice2=='7') { {    clrscr();
   Printf("This program calculate Cos x n");    clrscr();
   Printf("This program calculate Cos x n");    printf("Enter number ");    printf("Enter number ");    scanf("%lf",&cosx);    scanf("%lf",&cosx);    resultcos=cos(cosx);    resultcos=cos(cosx);    printf("The Cos of %lf is %lfn", cosx,resultcos);    printf("The Cos of %lf is %lfn", cosx,resultcos); } } else if(choice2=='8') else if(choice2=='8') { { clrscr(); clrscr(); printf("This program calculate Tan x n"); printf("This program calculate Tan x n"); printf("Enter number ");
scanf("%lf",&tanx); resulttan=tan(tanx); printf("Enter number ");
scanf("%lf",&tanx); resulttan=tan(tanx); printf("The Tan of %lf is %lfn", cosx,resultcos); printf("The Tan of %lf is %lfn", cosx,resultcos); } } } }