Profile

Cover photo
Computer Programming
149 followers|4,223 views
AboutPostsPhotosVideos

Stream

Computer Programming

Shared publicly  - 
 
Scientific Calculator

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
#include<graphics.h>
class gr{

public:
void wlcm();
void sci();
};gr a;

class cal{
private:
double n1,n2,res,sum,mult; //declaration of private variable(s) and function(s)
double factr(double);
public:
//declaration of public functions

void add();
void sub();
void npr();
void mul();
void div();
void sqroot();
void square();
void ncr();
void tan_fun();
void sinin();
void power();
void cosin();
void tanin();
void menu();
void factrl();
void cos_fun();
void sin_fun();
void cube();
void inverse();
void log_fun();
void ln_fun();
void pro();
void mass();
}; cal c;
void gr::sci()
{
char arr1[20]="COMPUTER PROJECT";
for(int i=0;i<17;i++)
{
outtextxy(180,240,arr1);
delay(100);
}

}
void gr::wlcm() //function for welcome screen
{
setbkcolor(1);
setcolor(10);
settextstyle(4,0,10);
outtextxy(200,80,"ISP");
settextstyle(7,0,2);
sci();
settextstyle(3,0,1);
outtextxy(180,270,"( SCIENTIFIC CULCOLATOR )");
sleep(2);
clearviewport();
setbkcolor(BLACK);
setcolor(YELLOW);
settextstyle(7,0,4);
outtextxy (50,140,"DEVELOPED BY");
settextstyle(7,0,2);
outtextxy(150,205,"Zubair Iftikhar BSCS(C) & Aftab BSCS(C)");
sleep(2);
clearviewport();
closegraph();
}
void cal::add() //function for addition


{
clrscr();
sum=0;
int x=1;
char ch='y';
while(ch=='y'||ch=='Y')


{
clrscr();
gotoxy(9,5);
cout<< "A D D I T I O N : ";
cout<<"\n\t_______________";
if(x==1)
cout<<"\n\tEnter the 1st number : ";
else if(x==2)
cout<<"\n\tEnter the 2nd number : ";
else if(x==3)
cout<<"\n\tEnter the 3rd number : ";
else
cout<<"\n\tEnter the "<<x<<"th number : ";

cin>>n1;
sum=sum+n1;
if(x>=2)
{
cout<<"\n\tEnter more number ? (y/n) : ";

cin>>ch;
}
x++;
}
cout<<"\n\tAddition result : ";
cout<<sum;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::sub() //function for subtraction


{
clrscr();
gotoxy(9,5);
cout<<"S U B T R A C T I O N : ";
cout<<"\n\t_____________________";
cout<<"\n\tEnter the 1st number : ";
cin>>n1;
cout<<"\n\tEnter the 2nd number : ";
cin>>n2;
res=n1-n2;
cout<<"\n\tSubtraction result : ";
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::mul() //function for multiplication


{
clrscr();
mult=1;
int x=1;
char ch='y';
while(ch=='y'||ch=='Y')


{
clrscr();
gotoxy(9,5);
cout<<"M U L T I P L I C A T I O N : ";
cout<<"\n\t___________________________";
if(x==1)
cout<<"\n\tEnter the 1st number : ";
else if(x==2)
cout<<"\n\tEnter the 2nd number : ";
else if(x==3)
cout<<"\n\tEnter the 3rd number : ";
else
cout<<"\n\tEnter the "<<x<<"th number : ";

cin>>n1;
mult=mult*n1;
if(x>=2)


{
cout<<"\n\tEnter more number ? (y/n) : ";
go1:
cin>>ch;
}
x++;
}
cout<<"\n\tMultiplication result : ";


cout<<mult;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::div() //function for division


{
clrscr();
gotoxy(9,5);
cout<<"D I V I S I O N : ";
cout<<"\n\t_______________";
cout<<"\n\tEnter the 1st number : ";
cin>>n1;
cout<<"\n\tEnter the 2nd number : ";
cin>>n2;
res=n1/n2;
cout<<"\n\tDivision result : ";
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::sqroot() //function for square root


{
clrscr();
gotoxy(9,5);
cout<<"S Q U A R E R O O T : ";
cout<<"\n\t____________________";
cout<<"\n\tEnter the number : ";
cin>>n1;
cout<<"\n\tSquare root : ";
cout<<sqrt(n1);
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::square() //function for square


{
clrscr();
gotoxy(9,5);
cout<<"S Q U A R E : ";
cout<<"\n\t___________";
cout<<"\n\tEnter the number : ";
cin>>n1;
cout<<"\n\tSquare : ";
cout<<pow(n1,2);
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::power() //function for power


{
clrscr();
gotoxy(9,5);
cout<<"P O W E R : ";
cout<<"\n\t_________";
cout<<"\n\tEnter the number : ";
cin>>n1;
cout<<"\n\tEnter the power : ";
cin>>n2;
cout<<"\n\tResult : ";
cout<<pow(n1,n2);
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::factrl() //function for factorial


{
clrscr();
gotoxy(9,5);
cout<<"F A C T O R I A L : ";
cout<<"\n\t_________________";
cout<<"\n\tEnter the integer : ";
cin>>n1;
if(n1<0)


{
cout<<"\n\tSyntax error.\a";
cout<<"\n\tPress any key to goto the main menu. ";
}
else


{
if(n1==1||n1==0)
res=1;
else
res=factr(n1);
cout<<"\n\tFactorial : ";
cout<<res;
cout<<"\n\tPress any key to goto the main menu. ";

}
}
double cal::factr(double p) //function for determining factorial


{
if(p>1)
p=p*factr(p-1);
return(p);
}
void cal::ncr() //function for nCr


{
clrscr();
gotoxy(9,5);
cout<<"n C r : ";
cout<<"\n\t_____";
cout<<"\n\tValue of 'n' : ";
cin>>n1;
cout<<"\n\tValue of 'r' : ";
cin>>n2;
if(n1<0 || n2<0 || n1<n2)


{
cout<<"\n\tSyntax error.";
cout<<"\n\tPress any key to goto the main menu.";

cout<<"\a";
}
else


{
if(n1==0 && n2==0)
res=1;
else if(n1>0 && n2==0)
res=1;
else if(n1==n2)
res=1;
else
res=factr(n1)/(factr(n2)*factr(n1-n2));
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
}
void cal::npr() //function for nPr


{
clrscr();
gotoxy(9,5);
cout<<"n P r : ";
cout<<"\n\t_____";
cout<<"\n\tValue of 'n' : ";
cin>>n1;
cout<<"\n\tValue of 'r' : ";
cin>>n2;
if(n1<0 || n2<0 || n1<n2)


{
cout<<"\n\tSyntax error.";
cout<<"\n\tPress any key to goto the main menu.";

cout<<"\a";
}
else


{
if(n1==0 && n2==0)
res=1;
else if(n1>0 && n2==0)
res=1;
else if(n1==n2)
res=factr(n1);
else
res=factr(n1)/factr(n1-n2);
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
}
void cal::cube() //function for cube


{
clrscr();
gotoxy(9,5);
cout<<"C U B E : ";
cout<<"\n\t_______";
cout<<"\n\tEnter the number : ";
cin>>n1;
cout<<"\n\tCube : ";
cout<<pow(n1,3);
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::inverse() //function for inverse


{
clrscr();
gotoxy(9,5);
cout<<"I N V E R S E : ";
cout<<"\n\t_____________";
cout<<"\n\tEnter the number : ";
cin>>n1;
cout<<"\n\tInverse : ";
cout<<pow(n1,-1);
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::log_fun() //function for logarithm( base is = 10 )


{
clrscr();
gotoxy(9,4);
cout<<"L O G A R I T H M : ";
cout<<"\n\t_________________";
cout<<"\n\t*** log x *** ";
cout<<"\n\t 10 ";
cout<<"\n\t________________";
cout<<"\n\tValue of 'x' : ";
cin>>n1;
res=log10(n1);
cout<<"\n\tResult : ";
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::ln_fun() //function for ln ( base is = e )


{
clrscr();
gotoxy(9,5);
cout<<"*** ln (x) *** ";
cout<<"\n\t________________";
cout<<"\n\tValue of 'x' : ";
cin>>n1;
res=log(n1);
cout<<"\n\tResult : ";
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::sin_fun() //function for sin


{
clrscr();
gotoxy(9,5);
cout<<"*** sin(x) *** ";
cout<<"\n\t________________";
cout<<"\n\tValue of 'x' : ";
cin>>n1;
res=sin(n1*(3.14159265)/180);
cout<<"\n\tResult : ";
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::cos_fun() //function for cos


{
clrscr();
gotoxy(9,5);
cout<<"*** cos(x) *** ";
cout<<"\n\t________________";
cout<<"\n\tValue of 'x' : ";
cin>>n1;
res=cos(n1*(3.14159265)/180);
cout<<"\n\tResult : ";
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::tan_fun() //function for tan


{
clrscr();
gotoxy(9,5);
cout<<"*** tan(x) *** ";
cout<<"\n\t________________";
cout<<"\n\tValue of 'x' : ";
cin>>n1;
res=tan(n1*(3.14159265)/180);
cout<<"\n\tResult : ";
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::sinin() //function for sin^-1


{
clrscr();
gotoxy(9,5);
cout<<" -1 ";
cout<<"\n\t*** sin (x) *** ";
cout<<"\n\t__________________";
cout<<"\n\tValue of 'x' : ";
cin>>n1;
if((n1>1)||(n1<-1))


{
cout<<"\n\tSyntax error.";
cout<<"\n\tPress any key to go to the main menu.";

cout<<"\a";
}
else


{
res=asin(n1)*180/(3.14159265);
cout<<"\n\tResult : ";
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
}
void cal::cosin() //function for cos^-1


{
clrscr();
gotoxy(9,5);
cout<<" -1 ";
cout<<"\n\t*** cos (x) *** ";
cout<<"\n\t__________________";
cout<<"\n\tValue of 'x' : ";
cin>>n1;
if((n1>1)||(n1<-1))


{
cout<<"\n\tSyntax error.";
cout<<"\n\tPress any key to go to the main menu.";

cout<<"\a";
}
else


{
res=acos(n1)*180/(3.14159265);
cout<<"\n\tResult : ";
cout<<"\n\tPress any key to go to the main menu. ";

}
}
void cal::tanin() //function for tan^-1


{
clrscr();
gotoxy(9,5);
cout<<" -1 ";
cout<<"\n\t*** tan (x) *** ";
cout<<"\n\t__________________";
cout<<"\n\n\tValue of 'x' : ";
cin>>n1;
res=atan(n1)*180/(3.14159265);
cout<<"\n\tResult : ";
cout<<res;
cout<<"\n\tPress any key to go to the main menu. ";

}
void cal::menu() //function for displaying and controlling main menu


{
clrscr();
textcolor(CYAN);
cout<<"Scientific C A L C U L A T O R "<<endl;
cout<<" _______________________"<<endl;
cout<<"\tMAIN MENU :\n";
cout<<"\n\t_________";
cout<<"\n\t1--Addition \t\t\t\t11--nCr";
cout<<" \n\t2--Subtraction \t\t\t\t12--nPr";
cout<<" \n\t3--Multiplication\t\t\t13--Logarithm";
cout<<" \n\t4--Division \t\t\t\t14--ln";
cout<<" \n\t5--Square root { x^(1/2) } \t\t15--sin(x)";
cout<<"\n\t6--Square ( x^2 )\t\t\t16--cos(x)";
cout<<"\n\t7--Cube ( x^3 ) \t\t\t17--tan(x)";
cout<<"\n\t8--Inverse ( 1/x ) \t\t\t18--sin-1(x)";
cout<<" \n\t9--Power ( x^y )\t\t\t19--cos-1(x)";
cout<<" \n\t10--Factorial ( n! )\t\t\t20--tan-1(x)";
cout<<"\n\n\t21--EXIT FROM THIS PROGRAM.";
cout<<"\n\t( Select an option from 1 to 21 )";
cout<<" \n\t_______________________________";
cout<<"\n\tYour choice : ";
}
void cal::mass()
{

cout<<"\a\t\t\tchoose correct Option";
}

void cal::pro()
{
int xyx;
while(1)



{
clrscr();
menu();
gotoxy(30,20);
cin>>xyx;
switch(xyx)


{
case 1:
add();
getch();
break;
case 2:
sub();
getch();
break;
case 3:
mul();
getch();
break;
case 4:
div();
getch();
break;
case 5:
sqroot();
getch();
break;
case 6:
square();
getch();
break;
case 7:
cube();
getch();
break;
case 8:
inverse();
getch();
break;
case 9:
power();
getch();
break;
case 10:
factrl();
getch();
break;
case 11:
ncr();
getch();
break;
case 12:
npr();
getch();
break;
case 13:
log_fun();
getch();
break;
case 14:
ln_fun();
getch();
break;
case 15:
c.sin_fun();
getch();
break;
case 16:
cos_fun();
getch();
break;
case 17:
tan_fun();
getch();
break;
case 18:
sinin();
getch();
break;
case 19:
cosin();
getch();
break;
case 20:
tanin();
getch();
break;
case 21:

exit(0);
break;
default:
mass();
getch();
}
}
}

void main() //main

{

int mode,driver=DETECT;
clrscr();
initgraph(&driver,&mode,"e:\\tc\\bgi");
a.wlcm();
clrscr();
c.pro();
getch();
  }
Note this programing writen 5-6 month ago so any error plz tell
1
2
Jules Kamanzi's profile photoSheila Kay McIntyre's profile photoJonathan Sears's profile photoAdedotun Samuel's profile photo
5 comments
 
this is c++. download the microsoft visual studios 2012 
Add a comment...

Computer Programming

Shared publicly  - 
 
***********Compare two strings***********
int strcmp ( const char * str1, const char * str2 );
Compares the  string str1 to the string str2.
Example
#include <iostream.h>
#include <string.h>

int main ()
{
char str1[] = "apple";
char str2[80];
do {
cout<<"Guess my favourite fruit? ";
gets (str2);
} while (strcmp (str1,str2) != 0);
puts ("Correct answer!");
return 0;
}

Output:
Guess my favourite fruit? Banana
Guess my favourite fruit? Banana
Correct answer!
1
Add a comment...

Computer Programming

Shared publicly  - 
 
****** strcpy ********
strcpy (Destination string,source string):This function accepts 2 strings as parameter,1st one is destination string and 2nd is source string.This function copies source string to destination string.

Example
#include <iostream.h>
#include <string.h>
int main(void)
{
char src[]="Computer",arrych[15];
strcpy(arrych,src);
cout<<arrych<<" is copied to arrych string";
}
Output:spark is copied to arrych string.
1
Add a comment...

Computer Programming

Shared publicly  - 
 
****** STRING'S ******
*What are strings?
 STRING'S are nothing but the character array.The declaration of string (character array) is much similar to normal array declaration.Each string is terminated by '\0' as indication of string termination.So obviously you will require an extra byte of memory for storing '\0'.'\0' is single character whose ASCII (American Standard Code for Information Interchange) value is 0.

*How to initialize strings ?
 char site[]={'g','o',o','g','l','e','p', 'l',  'u',  's', };
char Site[]="STRING'S";

*How to take Input as string and print Output that string?

method 1:
 main()
{
char name[30];
  cout<<"Enter your name";
  cin>>name;
  cout<<name;
}

 method 3: 
  main()
{
char name[30];
cout<< "Enter your name";
  gets(name);  
puts(name);
}

Difference between both ways is that 1st Method use's cin and in second Method  uses built-in function.
In 1st Method  if you Enter something like Computer Programming
it will take only Computer  as string and any thing after (space) will be discarded.In second Method if you enter any space it will be accepted.Output of second way would be Computer Programming .

Next posts on Strings built-in functions
1
Add a comment...

Computer Programming

Shared publicly  - 
 
#include <iostream.h>
#include <conio.h>

void main()
{
    char a = 'A', b = 'l', c = 'i';
    cout << "name is " << a << b << c;
    getch();
}
1
Add a comment...

Computer Programming

Shared publicly  - 
 
#include <iostream.h>
#include <string.h>

int main ()
{
string str = "Hello";
cout << "str is : " << str << endl;
str += ",";
str += ' ';
cout << "str is : " << str << endl;

string s;
s = str + "World";
cout << "s is : " << s << endl;

char ch = '!';
s += ch;
cout << "s is : " << s << endl;

return 0;
}
OUTPUT:
// str is : Hello
// str is : Hello,
// s is : Hello, World
// s is : Hello, World!
1
Add a comment...
Have them in circles
149 people

View all

Computer Programming

Shared publicly  - 
 
******  Compare Strings Without Case Sensitivity*********
strcmpi (string 1, string2):This function is similar to strcmp().The only difference is that it ignores the case.example ComPuter and computer both are same.

Example
  #include <iostream.h>
#include <string.h>
 int  main(void)
{
  char str1[]=" computer",str2[]=" ComPuter";
  int comp;
comp =strcmpi(str1,str2);
if( comp>0)
  cout<<str1<<">"<<str2;
else
{
if( comp<0)
  cout<<str1<<"< "<<str2;
else
 cout<<str1<<" = "<<str2;
}
}

Output: computer =  ComPuter

OR

#include <stdio.h>
#include <string.h>
int main(void)
{
/* Compare two strings without regard to case */
if (0 == strcmpi("hello", "HELLO"))
printf("The strings are equivalent.\n");
else
printf("The strings are not equivalent.\n");
return 0;
}

The output should be:
The strings are equivalent.
1
Add a comment...

Computer Programming

Shared publicly  - 
 
*************** Get string length ******************
size_t strlen ( const char * str );

Returns the length of the C/C++ string str.

 The length of a C++ string is determined by the terminating null-character: A C++ string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).

This should not be confused with the size of the array that holds the string. For example:

char mystr[100]="test string";

Example:
#include <iostream.h>
#include <string.h>

int main ()
{
char str[256];
cout<<"Enter a sentence: ";
gets (str);
cout<<"The sentence entered is"<<strlen(str)<<" characters long.";
return 0;
}

Enter sentence: Hello
The sentence entered is 5 characters long.
1
Add a comment...

Computer Programming

Shared publicly  - 
 
******* strlen()******** 
strlen():This function accepts string as parameter and return integer i.e the length of String passed to it.
syntax: int  strlen()  // here int is return data type of  strlen()  function.
Example
  #include <iomanip.h>
#include <string.h>
  #include <iostream.h> 
 main()
{
  char string[]="Computer";
int len;
len=strlen(string);
  cout<<"length of  is "<<string<<len;
}

Output::length of Computer is 8.
 
1
Add a comment...

Computer Programming

Shared publicly  - 
 
Declaring and Initializing an Array of Char
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int i=0,total=0,Number[] = { 10, 112, 41, 45, 37, 30, 31, 31, 3, 32, 39, 98 };
for(;i<12;i++)
{
cout<<Number[i]<<endl;
total=total+Number[i];
}
cout<<endl<<total;
getch();
}
1
Computer Programming's profile photoPadmanaban M's profile photo
3 comments
 
Thank you!!
Add a comment...
People
Have them in circles
149 people
Communities
Created by Computer Programming
View all
IT Village's profile photo
9 members
Story
Tagline
computer programming,learn languages(C,C++,Java, and also webdevelopment Languages HTML,CSS,Javascripts,PHP) and share our programmes