#include<iostream> using namespace std; void description(); void Derivative_calculations(); //void formulas(); //void Equation_calculations(); int main() { int choice; double num,exp; char Ans, Repeat_program; description(); do { cout <<"What would you like to calculate?"; cout << endl; cout << "1.Derivative Calculations"; cout << endl; cout << "2.Formulas"; cout << endl; cout << "3.Equation Calculations"; cout << endl; cout << "Enter your choice: "; cin >> choice; cout << endl; while (choice == 1) { Derivative_calculations(); cout << endl << endl; cout <<"would you like to continue calculating derivatives?: "; cin >> Ans; if ((Ans == 'Y')(Ans == 'y')) { choice = 1; } else if ((Ans == 'N')(Ans == 'n')) { choice = 0; } } while (choice == 2) { //formulas(); } while(choice == 3) { //Equation_calculations(); } cout <<"Would you like to continue running this Program?:"; cin >> Repeat_program; cout << endl; }while((Repeat_program == 'y')(Repeat_program == 'Y')); cout << endl << endl; cout << "<Program End>"; cout << endl << endl; system("Pause"); } void description() { cout <<"welcome to the program math operations"; cout << endl; cout << "this program is useful for many areas of mathematics"; cout << endl; } void Derivative_calculations() { int choice_1; double num,exp; char variable; cout << endl << endl; cout << "what kind of derivative would you like to find?"; cout << endl; cout << "1.single derivative"; cout << endl; cout << "2.Product Rule"; cout << endl; cout << "3.Quotient Rule"; cout << endl; cin >> choice_1; if(choice_1 == 1) { double number, number1, exponent, exponent1; char variable, carrot; cout << "example: f(x) = 2x^3\n"; cout << "example: f(x) = 2 enter as 2  ^ 1"; cout << endl; cout << "example: f(x) = x^4 enter as 1x^4"; cout << endl; cout << "Enter the function as given in example:" << endl; cin >> number >> variable >> carrot >> exponent; if((variable == '')&&(exponent == 1)) { cout << endl; cout << "the derivative of: " <<number << " is " << "0"; cout << endl << endl; } if((variable == 'X')(variable == 'x')) { number1 = number * exponent; exponent1 = exponent  1; if(exponent1 == 1) { cout << "the derivative of function: "<< number << variable << "^" << exponent; cout << endl; cout << endl << "is " << number1 << variable; cout << endl << endl; } if(exponent1 == 0) { cout << "the derivative of function: "<< number << variable << "^" << exponent; cout << endl; cout << endl << "is " << number1; } if((exponent1 != 0)&&(exponent1 != 1)) { cout << "the derivative of function: "<< number << variable << "^" << exponent; cout << endl; cout << endl << "is " << number1 << variable << "^" << exponent1; } } } }
Math Operations Program
Page 1 of 15 Replies  2301 Views  Last Post: 11 January 2013  09:07 AM
#1
Math Operations Program
Posted 10 January 2013  10:19 AM
Thought I'd Share my project. I call it Math Ops
Replies To: Math Operations Program
#2
Re: Math Operations Program
Posted 10 January 2013  01:39 PM
To be clear  This isn't a shared project. Its your homework.
We can't share every piece of week one homework that all of our 500,000+ members have.
A shared project is meant to be a community opensource project where developers can collaberate.
For example: Hosted projects on Google Code
We can't share every piece of week one homework that all of our 500,000+ members have.
 It would be a HUGE amount of storage
 It shows LOTS of really bad coding practice that we don't want to promote.
A shared project is meant to be a community opensource project where developers can collaberate.
For example: Hosted projects on Google Code
#3
Re: Math Operations Program
Posted 10 January 2013  09:19 PM
Nope i dont have such homework.. If you want to check my classes i can tell you that. I graduated from High School in 2010.. Dude and just to be clear i am on break. Thanks
www.ahmerjaved.webs.com
Here is my website you can check it out!!
www.ahmerjaved.webs.com
Here is my website you can check it out!!
#4
Re: Math Operations Program
Posted 10 January 2013  09:27 PM
Hey Ahmer,
When I ran your program in VS 2010, I had this problem.
I chose 1.Derivative Calculations and in that I chose 1. Single Derivative.
I entered the value and it ran successfully. Then I entered y and it asked me to enter a derivative
I entered it again and this time...it went into an infinite loop.
I have a suggestion. Make an else statement for checking if user has entered derivative correctly...something like
This will prevent the control from becoming an infinite loop.
regards,
Raghav
When I ran your program in VS 2010, I had this problem.
I chose 1.Derivative Calculations and in that I chose 1. Single Derivative.
I entered the value and it ran successfully. Then I entered y and it asked me to enter a derivative
I entered it again and this time...it went into an infinite loop.
I have a suggestion. Make an else statement for checking if user has entered derivative correctly...something like
else { cout<<"you have not entered the derivative as specified. Please enter again"; }
This will prevent the control from becoming an infinite loop.
regards,
Raghav
#5
Re: Math Operations Program
Posted 11 January 2013  08:56 AM
raghav.naganathan, on 10 January 2013  09:27 PM, said:
Hey Ahmer,
When I ran your program in VS 2010, I had this problem.
I chose 1.Derivative Calculations and in that I chose 1. Single Derivative.
I entered the value and it ran successfully. Then I entered y and it asked me to enter a derivative
I entered it again and this time...it went into an infinite loop.
I have a suggestion. Make an else statement for checking if user has entered derivative correctly...something like
This will prevent the control from becoming an infinite loop.
regards,
Raghav
When I ran your program in VS 2010, I had this problem.
I chose 1.Derivative Calculations and in that I chose 1. Single Derivative.
I entered the value and it ran successfully. Then I entered y and it asked me to enter a derivative
I entered it again and this time...it went into an infinite loop.
I have a suggestion. Make an else statement for checking if user has entered derivative correctly...something like
else { cout<<"you have not entered the derivative as specified. Please enter again"; }
This will prevent the control from becoming an infinite loop.
regards,
Raghav
Thank you for your Help and i will fix that. Thanks for point that out
#6
Re: Math Operations Program
Posted 11 January 2013  09:07 AM
/* Name: Mathops Copyright: Ahmer Javed Author: Ahmer Javed Date: 10/01/13 23:21 Description: Does multiple operations in Mathematics */ #include<iostream> #include<cmath> #include<conio.h> using namespace std; void description(); void Derivative_calculations(); void formulas(); //void Equation_calculations(); int main() { int choice; double num,exp; char Ans,Ans2,Ans3,Repeat_program; description(); do { cout <<"What would you like to calculate?"; // options to the user cout << endl; cout << "1.Derivative Calculations"; cout << endl; cout << "2.Formulas"; cout << endl; cout << "3.Equation Calculations"; cout << endl; cout << "Enter your choice: "; cin >> choice; cout << endl; // While option 1 is chosen while (choice == 1) { Derivative_calculations(); cout << endl << endl; cout <<"would you like to continue calculating derivatives?: "; cin >> Ans; if ((Ans == 'Y')(Ans == 'y')) { choice = 1; }// closes if ((Ans == 'Y')(Ans == 'y')) else if ((Ans == 'N')(Ans == 'n')) { choice = 0; } // closes else if ((Ans == 'N')(Ans == 'n')) }// closes while (choice == 1) while (choice == 2) { formulas(); cout << endl << endl; cout <<"would you like to continue calculating Formulas: "; cin >> Ans2; if ((Ans2 == 'Y')(Ans2 == 'y')) { choice = 1; }// closes if ((Ans2 == 'Y')(Ans2 == 'y')) else if ((Ans2 == 'N')(Ans2 == 'n')) { choice = 0; } // closes else if ((Ans2 == 'N')(Ans2 == 'n')) } // closes while (choice == 2) while(choice == 3) { //Equation_calculations(); }// closes while(choice == 3) cout <<"Would you like to continue running this Program?:"; // asks user if they want to repeat the program cin >> Repeat_program; cout << endl; }while((Repeat_program == 'y')(Repeat_program == 'Y')); cout << endl << endl; cout << "<Program End>"; cout << endl << endl; system("Pause"); }// closes int main() void description() { cout <<"welcome to the program math operations"; cout << endl; cout << "this program is useful for many areas of mathematics"; cout << endl; }// close void description() void Derivative_calculations() // code from derivative program { int choice_1; double num,exp; char variable; cout << endl << endl; cout << "what kind of derivative would you like to find?"; cout << endl; cout << "1.single derivative"; cout << endl; cout << "2.Product Rule"; cout << endl; cin >> choice_1; if(choice_1 == 1) { double number, number1, exponent, exponent1; char variable, carrot; cout << "example: f(x) = 2x^3\n"; cout << "example: f(x) = 2 enter as 2  ^ 1"; cout << endl; cout << "example: f(x) = x^4 enter as 1x^4"; cout << endl; cout << "Enter the function as given in example:" << endl; cin >> number >> variable >> carrot >> exponent; if((variable == '')&&(exponent == 1)) { cout << endl; cout << "the derivative of: " <<number << " is " << "0"; cout << endl << endl; }// closes if((variable == '')&&(exponent == 1)) if((variable == 'X')(variable == 'x')) { number1 = number * exponent; exponent1 = exponent  1; if(exponent1 == 1) { cout << "the derivative of function: "<< number << variable << "^" << exponent; cout << endl; cout << endl << "is " << number1 << variable; cout << endl << endl; }// closes if((variable == 'X')(variable == 'x')) if(exponent1 == 0) { cout << "the derivative of function: "<< number << variable << "^" << exponent; cout << endl; cout << endl << "is " << number1; }// closes if(exponent1 == 0) if((exponent1 != 0)&&(exponent1 != 1)) { cout << "the derivative of function: "<< number << variable << "^" << exponent; cout << endl; cout << endl << "is " << number1 << variable << "^" << exponent1; } // closes if statement if((exponent1 != 0)&&(exponent1 != 1)) }// closes if statement ((variable == 'X')(variable == 'x')) }// closes if(choice_1 == 1) if(choice_1 == 2) { double number, exponent; double number_1, exponent_1; double number_2, exponent_2; double number_sol, exponent_sol; double number_sol_1, exponent_sol_1; char Parenthesis; char variable, carrot; char variable_1; char variable_2; cout << "example: (2x^3)(3^4)"; cout << endl; cout << "example: 2 enter as (2^1)"; cout << endl; cout << "Enter functions just like example:" << endl; cin >> Parenthesis >> number >> variable >> carrot >> exponent >> Parenthesis; cin >> Parenthesis >> number_1 >> variable_1>> carrot >> exponent_1>>Parenthesis; if((variable == '')(variable_1 == '')) { if(variable == '') { number = pow(number,exponent); number_sol = number * number_1; number_sol = number_sol * exponent_1; exponent_sol = exponent_1  1; cout <<"The derviative is: "<<number_sol << variable_1 << "^" << exponent_sol; }// closes if(variable == '') if(variable_1 == '') { number_1 = pow(number_1, exponent_1); number_sol = number * number_1; number_sol = number_sol * exponent; exponent_sol = exponent  1; cout <<"The first derviative is: "<<number_sol << variable << "^" << exponent_sol; }// closes if(variable_1 == '') }// closes if((variable == '')(variable_1 == '')) if((variable_1 == 'x')&&(variable == 'x')) { number_sol = number * number_1; exponent_sol = exponent + exponent_1; number_sol = exponent_sol * number_sol; exponent_sol = exponent_sol  1; cout <<"The first derviative is: "<<number_sol << variable << "^" << exponent_sol; }// closes if((variable_1 == 'x')&&(variable == 'x')) cout << endl; number_sol_1 = number_sol * exponent_sol; exponent_sol_1 = exponent_sol  1; if(exponent_sol_1 == 1) { cout <<"The second derivative is: "<<number_sol_1 << "x"; }// closes if(exponent_sol_1 == 1) if(exponent_sol_1 > 1) { cout <<"The second derivative is: "<<number_sol_1 << "x" << "^"<< exponent_sol_1; }// closes if(exponent_sol_1 > 1) if(exponent_sol_1 < 1) { cout <<"The second derivative is: "<<number_sol_1; } // closes if(exponent_sol_1 < 1) } // closes if statement ((variable == 'X')(variable == 'x')) }// closes function void Derivative_calculations() void formulas() { int choice_3; cout <<"what formula would you like to run?"; //asks user cout << endl; cout <<"1. Temprature conversion (from F to C and vice versa)"; // Temp program cout << endl cout <<"2. Square Area Formula"; // from geo program cout << endl; cout <<"3. Circle area formula"; // From geo Program cout << endl; if (choice_3 == 1) { int ch; float ctemp,ftemp; cout <<"1.celsius to Fahrenheit" << endl; cout <<"2.Fahrenheit to Celsius" << endl; cout << "choose between 1&2: " << endl; cin >> ch; if (ch == 1) { cout << "Enter the temprature in Celsius :" << endl; cin >> ctemp; ftemp = (1.8*ctemp)+32; cout << "temprature in Farenheit =" << ftemp << "F" <<endl; }// closes if (choice == 1) else { cout <<"Enter the temprature in Fahrenheit:" << endl; cin >> ftemp; ctemp = (ftemp  32)/1.8; cout <<"temprature in celsius = " << ctemp << "C" << endl; }// closes else statement }// closes if (choice_3 == 1)
Had to comment each brace to avoid confusion on what each brace does. Please let me know if i can make this program simpler? or recommend changes i could do
Page 1 of 1
