Post your C/C++ Programs Here

Status
Not open for further replies.
Turbo Calc 15000

TURBO CALC 15000

This is a basic calculator compiled using GCC, but first written using Borland's Turbo C++ IDE 3.0, hence called turbo calc. It has 15 functions, hence 15000

Code:
/* 
 Turbo Calc 11000 Coppyright(c) Gautham T 
 
 This is freeware, use this software as you 
 like, but the author must be attributed to 
 when making derivatives. This source code may 
 also be distributed with it. Its delivered under 
 GNU GPL Version 3, a coppy of which may be found in 
 www.gnu.org . This software is Designed to 
 illustrate some basic operations with C++ 
 and it uses Turbo C++ IDE 3.0 for compiling 
 although source code is easily ported to 
 other platforms. 
 */ 
 
#include<iostream.h> 
#include<math.h> 
 
/* iostream.h for basic operations 
   conio.h for clrscr() 
   math.h for many of the calculator's functions */ 
 
int main()                                    //calculator function 
 
{ 
 
long double a,b;                               //the two operants 
 
unsigned short int c;                          //choice 
 
cout<<"This is turbocalc 11000, your best choice for a"<<endl; 
cout<<"simple and robust x86 platform based calculator."<<endl<<endl; 
 
cout<<"Type  1 for addition;"<<endl;                           //add 
cout<<"Type  2 for subtraction;"<<endl;                        //sub 
cout<<"Type  3 for multiplication;"<<endl;                     //multi 
cout<<"Type  4 for dividion;"<<endl;                           //div 
cout<<"Type  5 for finding the Square;"<<endl;                 //square 
cout<<"Type  6 for finding the Cube;"<<endl;                   //cube 
cout<<"Type  7 for finding the square root;"<<endl;            //root 
cout<<"Type  8 for finding the sine;"<<endl;                   //sin 
cout<<"Type  9 for finding the cosine;"<<endl;                 //cos 
cout<<"Type 10 for finding the tangent;"<<endl;                //tan 
cout<<"Type 11 for finding the seccant;"<<endl;                //sec 
cout<<"type 12 for finding the coseccant;"<<endl;              //cosec 
cout<<"Type 13 for finding the cotangent;"<<endl;              //cot     
cout<<"Type 14 for finding the natural logarithm;"<<endl;      //log 
cout<<"Type 15 for finding the logarithm to base 10."<<endl;   //log10 
 
cin>>c;                                            //got the choice now 
 
if ((c==1)||(c==2)||(c==3)||(c==4)) 
{ 
cout<<"Enter the first number:"<<endl; 
cin>>a; 
cout<<endl<<endl<<"Enter the second number:"<<endl; 
cin>>b; 
} 
else if((c==5)||(c==6)||(c==7)||(c==8)||(c==9)||(c==10)||(c==11)||(c==12)||(c==13)||(c==14)||(c==15)) 
{ 
cout<<"enter the number: "<<endl; 
cin>>a; 
} 
else 
{ 
cout<<"You must only enter a number from 1 to 15."<<endl; 
} 
 
if (c==1) 
cout<<"The Sum is     "<<a+b<<endl; 
 
else if (c==2) 
cout<<"The Difference is      "<<a-b<<endl; 
 
else if (c==3) 
cout<<"The Product is     "<<a*b<<endl; 
 
else if (c==4) 
cout<<"The Quotient is     "<<a/b<<endl; 
 
else if (c==5) 
cout<<"The Square is     "<<a*a<<endl; 
 
else if (c==6) 
cout<<"The Cube is     "<<a*a*a<<endl; 
 
else if (c==7) 
cout<<"The Square Root is     "<<sqrt(a)<<endl; 
 
else if (c==8) 
cout<<"The Sine is     "<<sin(a)<<endl; 
 
else if (c==9) 
cout<<"The Cosine is     "<<cos(a)<<endl; 
 
else if (c==10) 
cout<<"The Tangent is     "<<tan(a)<<endl; 
 
else if (c==11) 
cout<<"The Seccant is     "<<1/(cos(a))<<endl; 
 
else if (c==12) 
cout<<"The Coseccant is     "<<1/(sin(a))<<endl; 
 
else if (c==13) 
cout<<"The Cotangent is     "<<1/(tan(a))<<endl; 
 
else if (c==14) 
cout<<"The Natural Logarithm is     "<<log(a)<<endl; 
 
else if (c==15) 
cout<<"The Logarithm to base 10 is     "<<log10(a)<<endl; 
 
else 
cout<<"There must be an error in what you typed."<<endl<<"Try Again."; 
 
return 0; 
}
PS: I am a rookie C++ programmer. I had learnt C in the begening of class 6(lol) but forgot it(lol again)

I made this because I just wanted to try something that looks usable. Please excuse my n00bishness

I regret the fact that we have only Turbo C++ in CBSE senior secondary scyllabus. Anjuta IDE and Dev-Cpp along with MinGW Developer Studio are forgotton. CBSE I suppose, is full fo linux haters.
 

Nav11aug

In the zone
Re: Post ur C/C++ Programs Here

I dunno if it has Linux-haters or Linux-illiterates, and puttin in Linux won't help. We have enough dumb teachers anyway
 

[xubz]

"The Cake is a Lie!!"
Re: Post ur C/C++ Programs Here

Gigacore said:
did anyone try the turbo calc ?

i've prob with my compiler.. :(
Working Fine here.

Used Borland C++ 5.5 and VIM (heh, I use vim even in windows ^_^)

@MetalheadGautham -> You can use Switch-Case instead of Insane no if nested-if for just validating a single number :)
 
Re: Post ur C/C++ Programs Here

You can use Switch-Case instead of Insane no if nested-if for just validating a single number
know it... but I still prefer if clause...

It worked now for me in Dev C++.. nice program.. keep it up!
nice program? isn't this supposed to be a n00bish bit of code?(what else can you expect from a cbse programmer?)
 

Sykora

I see right through you.
Re: Post ur C/C++ Programs Here

Offtopic :

nice program? isn't this supposed to be a n00bish bit of code?(what else can you expect from a cbse programmer?)

Oi! I may decide to take that as an insult :(

"Noobish code" is where you start on your way to greatness. Everyone does noobish code at the beginning. Just don't stay a noob for too long :) .

Ontopic : How can you say it compiled with gcc if you used nonstandard header files and outdated syntax?
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

MetalheadGautham said:
know it... but I still prefer if clause...
A switch() block is perhaps faster than an if-else cascading block. Its something to do with jump tables. C compilers automatically optimize a switch block into a branch/jump table.

But of course, it (switch) has its limitations too, like handling only integral data types (No strings, etc).
 

[xubz]

"The Cake is a Lie!!"
Re: Post ur C/C++ Programs Here

A Command Line Calculator.

I coded this because sometimes if I quickly wanted to multiply/divide some numbers, I'd hate to open up the Calculator App (especially in Linux).

Just cal 2 + 2 or cal 100 / 39 would throw up the result. Much Better :)

Code:
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char *argv[])
{
	float a, b;
	char op;

	if (argc < 4 || argc > 4)
	{
		printf("\nUsage: cal <number1> <operator> <number2>\n");
		printf("\nValid Expressions: + - * /\n");
		printf("\nExample: cal 2 + 2\n");
		exit(1);
	}

	/* Store the Command Line Arguments in Local Variables */
	a = atof(argv[1]);
	b = atof(argv[3]);
	op = *argv[2];

	switch(op)
	{
		case '+':
			printf("\n%f", (float)a+b);
			break;

		case '-':
			printf("\n%f", (float)a-b);
			break;

		case '*':
			printf("\n%f", (float)a*b);
			break;

		case '/':
			printf("\n%f", (float)a/b);
			break;

		default:
			printf("\nInvalid Operator");
			break;
	}

	printf("\n");
	return(0);
}

Tested to compile and work using GCC under Linux
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

[xubz] said:
I'd hate to open up the Calculator App (especially in Linux).
You can use the bash math commands like bc, it supports floating point calculations.

Use bc filename if you have the math expressions stored in a file line by line.

Or use bc <enter> to enter the interactive mode.

Or even use echo expression | bc to pipe it to bc without a file or interaction.

Don't forget to use man bc or info bc ;)

The other bash commands I know of are dc (reverse polish calculator) and factor (splits a number to its factors).

I think there's also a package for scientific calculation via CLI, its called wcalc.
 
Last edited:

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Python loaded with os module (>>> import os) would be great, run bash and python commands together from within the python shell :D
 

Sykora

I see right through you.
Re: Post ur C/C++ Programs Here

But using the output of shell commands within python is moderately difficult. Although the os module does give you the tools, it takes some time to learn them. (os.popen)

It's a long time since I used a "calculator" app. python with ipython shell is bliss. So is sage.
 

[xubz]

"The Cake is a Lie!!"
Re: Post ur C/C++ Programs Here

Hmmm, Python Shells, Google-ing revealed PyShell, Lemme Try it :p
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Yeah PyShell is there too, but its sort of weak at its work. Don't use it as a replacement for bash! :p
 

srikanth.9849671439

BE THE FIRST OR LAST
Re: Post ur C/C++ Programs Here

1)wrap such that the oupput should be az,by,cx,dw.........................
2)wrap such that the oup put should be 1+10,2+9,3+8..........5+6
3)print the numbers in pyramid shape.......
1
2 2
3 3 3
4 4 4 4
4) print
y
z y z
r z y z r
z y z
y
 

sandeep9796

Right off the assembly line
Re: Post ur C/C++ Programs Here

hmmmmmmmmmm

i m tryin to make and application tht will generate a listin of files in a directory and display them????

anyone knows how to do it???
 

mehulved

18 Till I Die............
Re: Post ur C/C++ Programs Here

sandeep9796 said:
hmmmmmmmmmm

i m tryin to make and application tht will generate a listin of files in a directory and display them????

anyone knows how to do it???
I guess this should help *minnie.tuhs.org/UnixTree/V7/usr/src/cmd/ls.c.html
 

nvidia

-----ATi-----
Re: Post ur C/C++ Programs Here

srikanth.9849671439 said:
3)print the numbers in pyramid shape.......
1
2 2
3 3 3
4 4 4 4
I dont know how to do the first 2 and the 4th one. Here is the answer to the 3rd:
Code:
#include <stdio.h>
#include <conio.h>

void main()
{
 int i,j;
 for(i=1;i<=4;i++)
  {
    for(j=1;j<=i;j++)
    printf("%d\t" , i);
    printf("\n");
  }
 getch();
}
 

girish.g

respect mah authoritah!!
Re: Post ur C/C++ Programs Here

please help in the following programs
1 finding triangle matrix in a given matrix
2 to find sum of series: x-(x^2)/3!+(x^3)/5!-(x^4)/7!+(x^5)/9!.......... upto n terms(where x^2 is x square x^3 is x cube and so on and ! is factorial)
3 to convert binary to decimal
please this is urgent as i have to submit a project in school
 
Status
Not open for further replies.
Top Bottom