/* Project of Standard Calculator in C & C++ “( Calculator , Algebra Formula , Statistics)”.*/
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
#include<dos.h>
class Starting {
public:
void loading() { //project loading... 10 sec
int gd=DETECT,gm,i,a[7]={0,0,0,0,0,0,0};
initgraph(&gd,&gm,"..\bgi");
for(i=0; i<100; i++,a[0]+=20,a[1]+=20,a[2]+=20,a[3]+=20,
a[4]+=20,a[5]+=20,a[6]+=20)
{
clearviewport();
rectangle(20,20,600,450);
rectangle(70,70,550,400);
outtextxy(150,110,"Standard Calculator");
settextstyle(10,0,3);
rectangle(140,250,500,300);
pieslice(160+a[0],275,0,360,5);
pieslice(180+a[1],275,0,360,5);
pieslice(200+a[2],275,0,360,5 );
pieslice(220+a[3],275,0,360,5);
pieslice(240+a[4],275,0,360,5);
pieslice(260+a[5],275,0,360,5);
pieslice(280+a[6],275,0,360,5);
if(a[0]==320)
a[0]=0;
if(a[1]==300)
a[1]=0;
if(a[2]==280)
a[2]=0;
if(a[3]==260)
a[3]=0;
if(a[4]==240)
a[4]=0;
if(a[5]==220)
a[5]=0;
if(a[6]==200)
a[6]=0;
delay(100);
}
closegraph();
} //end loading()
void developed_by() { //Developers Name
int gd=DETECT,gm;
int i;
initgraph(&gd,&gm,"..\bgi");
for(i=1;i<6;i++) {
clearviewport();
setcolor(3);
setfillstyle(9,3);
rectangle(20,50,580,380);
rectangle(50,70,550,360);
floodfill(30,60,3);
setcolor(10);
settextstyle(1,0,i);
outtextxy(155,120,"Developed by");
settextstyle(1,0,i);
outtextxy(70,220,"Prashant Goel & Vipul");
delay(200);
}
delay(3000);
closegraph();
}} ;
class Main_Menu {
public:
void main_menu_diagram() {
int gd=DETECT,gm;
initgraph(&gd,&gm,"..\bgi");
settextstyle(7,0,4);
outtextxy(120,50,"Standard Calculator");
line(280,85,280,120);
line(60,120,510,120);
line(60,120,60,150);
settextstyle(1,0,1);
outtextxy(0,150,"1: Calculator");
line(280,120,280,150);
outtextxy(190,150,"2: Algebric Formula");
line(510,120,510,150);
outtextxy(440,150,"3: Statistics");
}
void main_menu_command() {
char menu;
do {
main_menu_diagram();
menu=getch();
switch(menu) {
case '1': {
closegraph();
Calculator cal1;
cal1.calculator_function();
break;
}
case '2': {
closegraph();
Algebra algebra1;
algebra1.algebra_function();
break;
}
case '3': {
closegraph();
Statistics stat1;
stat1.statistics_menu_command();
break;
}
case 'e':
exit(0);
}
}while(menu!='4');
}
};
class Calculator{
public:
void calculator_function() { //start calculartor functions
float x;
char ch;
instructions_calculator();
printf("nEnter the Values:");
scanf("%f",&x);
do {
scanf("%c",&ch);
switch(ch) {
case '+': {
add(x);
break;
}
case '-': {
sub(x);
break;
}
case '*': {
mul(x);
break;
}
case '/': {
div(x);
break;
}
case 'r': {
root(x);
break;
}
case 'n': {
printf("=");
scanf("%f",&x);
break;
}
case 'c': {
clrscr();
break;
}
case 'i': instructions_calculator();
break;
case 'e':exit(0);
}
}while(ch!='b');
}
void instructions_calculator() {
printf("n---> CALCULATOR <---nn");
printf("'+' for addn");
printf("'-' for subn");
printf("'*' for muln");
printf("'/' for divn");
printf("'r' for sqrt rootn");
printf("'n' for Nulln");
printf("'c' for Clear the Screenn");
printf("'i' for Read the Instructions Againn");
printf("'e' for Exitn");
printf("'b' for Back to Main_Menun");
}
void add(float &x) {
float y;
scanf("%f",&y);
x=x+y;
printf("=%.2f",x);
}
void sub(float &x) {
float y;
scanf("%f",&y);
x=x-y;
printf("=%.2f",x);
}
void mul(float &x) {
float y;
scanf("%f",&y);
x=x*y;
printf("=%.2f",x);
}
void div(float &x) {
float y;
scanf("%f",&y);
x=x/y;
printf("=%.2f",x);
}
void root(float &x) {
x=sqrt(x);
printf("=%.4f",x);
} //end of all calculator functions
};
class Algebra{
public:
void algebra_function() { //Algebra functions start
char ch;
int a,b,c,res;
clrscr();
instructions_algebra();
do {
scanf("%c",&ch);
switch(ch) {
case '1': {
printf("Enter the value A and B:");
scanf("%d%d",&a,&b);
res=(a+b)*(a+b);
printf("(A+B)^2 =%d",res);
break;
}
case '2':{
printf("Enter the value A and B:");
scanf("%d%d",&a,&b);
res=(a-b)*(a-b);
printf("(A-B)^2 =%d",res);
break;
}
case '3':{
printf("Enter the value A and B:");
scanf("%d%d",&a,&b);
res=(a*a-b*b);
printf("(A^2-B^2) =%d",res);
break;
}
case '4':{
printf("Enter the value A and B:");
scanf("%d%d",&a,&b);
res=(a+b)*(a+b)*(a+b);
printf("(A+B)^3 =%d",res);
break;
}
case '5':{
printf("Enter the value A and B:");
scanf("%d%d",&a,&b);
res=(a-b)*(a-b)*(a-b);
printf("(A-B)^3 =%d",res);
break;
}
case '6':{
printf("Enter the value A and B:");
scanf("%d%d",&a,&b);
res=a*a*a+b*b*b;
printf("(A^3+B^3) =%d",res);
break;
}
case '7':{
printf("Enter the value A and B:");
scanf("%d%d",&a,&b);
res=a*a*a-b*b*b;
printf("(A^3-B^3) =%d",res);
break;
}
case '8':{
printf("Enter the value A and B and C:");
scanf("%d%d%d",&a,&b,&c);
res=(a+b+c)*(a+b+c);
printf("(A+B+C)^2=%d",res);
break;
}
case 'i':{ instructions_algebra();
break;
}
case 'c': clrscr();
break;
case 'e': exit(0);
}
}while(ch!='b');
}
void instructions_algebra(){
printf("n---> Algebra <---n");
printf("n'1' for (a+b)^2");
printf("n'2' for (a-b)^2");
printf("n'3' for (a^2 - b^2)");
printf("n'4' for (a+b)^3");
printf("n'5' for (a-b)^3");
printf("n'6' for (a^3 + b^3)");
printf("n'7' for (a^3 - b^3)");
printf("n'8' for (a+b+c)^2");
printf("n'i' for Read the Algebra instructions Again");
printf("n'c' for Clear the Screen");
printf("n'e' for Exit");
printf("n'b' for Back to Main_Menu");
printf("nnEnter your choice:");
}};
// end Algebra functions
class Statistics{
public:
void statistics_menu_diagram() {
int gd=DETECT,gm;
initgraph(&gd,&gm,"..\bgi");
settextstyle(10,0,3);
outtextxy(220,50,"Statistics");
delay(1000);
line(280,100,280,120);
line(60,120,510,120);
line(60,120,60,150);
settextstyle(1,0,1);
outtextxy(0,150,"1: Arithmetic Mean");
line(280,120,280,150);
outtextxy(240,150,"2: Median");
line(510,120,510,150);
outtextxy(460,150,"3: Mode");
}
void statistics_menu_command(){
char menu;
do {
statistics_menu_diagram();
menu=getch();
switch(menu) {
case '1':{
closegraph();
Arithmetic_Mean();
break;
}
case '2':{
closegraph();
Median();
break;
}
case '3':{
closegraph();
Mode();
break;
}
case 'e': exit(0);
}
}while(menu!='b');
}
void Arithmetic_Mean(){
char ch;
clrscr();
instruction_arithmetic_mean();
do {
scanf("%c",&ch);
switch(ch) {
case '1':individual_arithmetic_mean();
break;
case '2':discreet_arithmetic_mean();
break;
case '3':continous_arithmetic_mean();
break;
case 'i':instruction_arithmetic_mean();
break;
case 'c':clrscr();
break;
case 'e':exit(0);
}
}while(ch!='b');
}
void instruction_arithmetic_mean() {
printf("n---> ARITHMETIC MEAN <---n");
printf("n'1' for Individual Series");
printf("n'2' for Discreet Series");
printf("n'3' for Continious Series");
printf("n'i' for Read the Instructions Again");
printf("n'c' for Clear the screen");
printf("n'b' back");
printf("n'e' for Exit the programn");
}
void individual_arithmetic_mean() {
float x[20],n,i,total=0,am;
printf("nEnter the Total Observation:");
scanf("%f",&n);
printf("nEnter %.0f observations:n",n);
for(i=0;i<n;i++) {
scanf("%f",&x[i]);
total=total+x[i];
}
am=total/n;
printf("AM=%.3fn",am);
}
void discreet_arithmetic_mean() {
float n,i,x[20],f[20],fx[20],am,ftotal=0,fxtotal=0;
printf("nEnter the total Observations:");
scanf("%f",&n);
printf("nEnter %.0f observstion of X:n",n);
for(i=0;i<n;i++)
scanf("%f",&x[i]);
printf("nEnter %.0f Freq:n",n);
for(i=0;i<n;i++) {
scanf("%f",&f[i]);
fx[i]=x[i]*f[i];
ftotal=ftotal+f[i];
fxtotal=fxtotal+fx[i];
}
am=fxtotal/ftotal;
printf("AM=%.3fn",am);
}
void continous_arithmetic_mean() {
float n,i,l1,l2,x[20],f[20],fx[20],am,ftotal=0,fxtotal=0;
printf("nEnter the total Observations:");
scanf("%f",&n);
printf("nEnter %.0f observstion of X:n",n);
for(i=0;i<n;i++) {
printf("Enter the %.0f observation of CI:",i+1);
scanf("%f%f",&l1,&l2);
x[i]=(l1+l2)/2;
}
printf("nEnter %.0f Freq:n",n);
for(i=0;i<n;i++) {
scanf("%f",&f[i]);
fx[i]=x[i]*f[i];
ftotal=ftotal+f[i];
fxtotal=fxtotal+fx[i];
}
am=fxtotal/ftotal;
printf("nAM=%.3fn",am);
}
void Median() {
char ch;
clrscr();
instruction_median();
do {
scanf("%c",&ch);
switch(ch) {
case '1':individual_median();
break;
case '2':discreet_median();
break;
case '3':continous_median();
break;
case 'i':instruction_median();
break;
case 'c':clrscr();
break;
case 'e':exit(0);
}
}while(ch!='b');
}
void instruction_median() {
printf("n---> MEDIAN <---n");
printf("n'1' for Individual Series");
printf("n'2' for Discreet Series");
printf("n'3' for Continious Series");
printf("n'i' for Read the Instructions Again");
printf("n'c' for Clear the screen");
printf("n'b' back");
printf("n'e' for Exit the programn");
}
void individual_median() {
int n,i,x[15],m;
float md,md1;
printf("Enter the total observation:");
scanf("%d",&n);
printf("Enter the %d observations:n",n);
for(i=0;i<n;i++) {
scanf("%d",&x[i]);
}
assending(x,n); //call assending function
if(n%2!=0) {
m=(n+1)/2;
printf("Median is: %d",x[m-1]);
}
else {
m=n/2;
md=(x[m-1]+x[m]);
md1=md/2;
printf("Median is: %fn",md1);
}
}
void discreet_median() {
int n,i,x[15],f[15],cf[15],m;
printf("nEnter the total Observation:");
scanf("%d",&n);
printf("Enter the %d Observations for X:n",n);
for(i=0;i<n;i++)
scanf("%d",&x[i]);
printf("Now Enter the %d freq:n",n);
cf[-1]=0;
for(i=0;i<n;i++) {
scanf("%d",&f[i]);
cf[i]=cf[i-1]+f[i];
}
m=(cf[n-1]+1)/2;
printf("CF:n");
for(i=0;i<n;i++) {
printf("%dn",cf[i]);
}
for(i=0;i<n;i++) {
if(m<cf[i]) {
printf("nMedian is:%dn",x[i]);
break;
}
}
}
void continous_median() {
float n,i,l1[20],l2[20],x[20],f[20],cf[20],m,md;
printf("nEnter the total obsevations:");
scanf("%f",&n);
for(i=0;i<n;i++) {
printf("Enter the %1.0f observation of CI:",i+1);
scanf("%f%f",&l1[i],&l2[i]);
}
printf("Enter all frequency:n");
cf[-1]=0;
for(i=0;i<n;i++) {
scanf("%f",&f[i]);
cf[i]=cf[i-1]+f[i];
}
m=cf[n-1]/2;
for(i=0;i<n;i++) {
if(m<cf[i]) {
md=l1[i]+(((m-cf[i-1])*(l2[i]-l1[i]))/f[i]);
printf("Median is : %.4fn",md);
break;
}
}
}
void assending(int x[],int n) {
int i,j,temp;
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(x[i]>x[j]){
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}}}
void Mode(){
char ch;
clrscr();
instruction_mode();
do {
scanf("%c",&ch);
switch(ch) {
case '1':individual_mode();
break;
case '2':discreet_mode();
break;
// case '3':continous_mode();
// break;
case 'i':instruction_mode();
break;
case 'c':clrscr();
break;
case 'e':exit(0);
}
}while(ch!='b');
}
void instruction_mode() {
printf("n---> MODE <---n");
printf("n'1' for Individual Series");
printf("n'2' for Discreet Series");
printf("n'3' for Continious Series");
printf("n'i' for Read the Instructions Again");
printf("n'c' for Clear the screen");
printf("n'b' back");
printf("n'e' for Exit the programn");
}
void individual_mode(){
int n,a[10],i,j,k,freq,x[10],f[10],z=-1;
printf("Enter the total Observation:");
scanf("%d",&n);
printf("Enter the %d observation:",n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
for(j=0;j<i;j++){
if(a[i]==a[j])
goto lab;
}
freq=0;
for(k=i;k<n;k++){
if(a[i]==a[k])
freq++;
}
z++;
f[z]=freq;
x[z]=a[i];
//printf("n%d Frequency is:%d",a[i],freq);
lab:
}
for(i=0;i<=z;i++)
printf("n%d freq is:%d",x[i],f[i]);
j=f[0];
for(i=0;i<=z;i++){
if(j<=f[i]){
j=f[i];
k=i;
}
}
printf("nMode is:%dn",x[k]);
}
void discreet_mode(){
int x[20],f[20],i,n,max,position;
printf("nEnter the total Observation:");
scanf("%d",&n);
printf("nEnter %d observation if X:n",n);
for(i=0;i<n;i++)
scanf("%d",&x[i]);
printf("nEnter %d freequency:n",n);
for(i=0;i<n;i++)
scanf("%d",&f[i]);
max=f[0];
for(i=0;i<n;i++){
if(max<=f[i]){
max=f[i];
position=i;
}
}
printf("Mode is :%d , freq :%dn",x[position],max);
}
};
void main()
{
Starting st1;
st1.loading();
st1.developed_by();
Main_Menu main1;
main1.main_menu_command();
}
Output