Program Description
This program asks for three numbers from the user and outputs the highest number from the three.
Output
Source Code
Posted by Mark Darwin on September 7, 2010
Program Description
This program asks for three numbers from the user and outputs the highest number from the three.
Output
Source Code
Posted in C++ Source Codes | Leave a Comment »
Posted by Mark Darwin on October 24, 2009
Program Description
This program computes for the area of a circle, triangle or a rectangle. It uses if statements to choose from the three shapes. It also uses cmath for the exponents.
Output
When the computation of area of a circle is chosen:
When the computation of area of a rectangle is chosen:
When the computation of area of a triangle is chosen:
Source Code
#
To download the text file, click the link below:
Posted in C++ Source Codes | Tagged: Area, C plus plus, C++, Circle, cmath, Code, Codes, Computation, if, Program, Rectangle, Source, Source Code, Source Codes, statements, Triangle, Tutorials | Leave a Comment »
Posted by Mark Darwin on October 23, 2009
New C++ Tutorials are posted. These are lesson 4 and 5 which discusses data types and arithmetic operators. Here’s the link for the pages of these lessons:
Lesson4: Data Types and Declaration of Variables
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Lesson5: Operators, Expressions and Operator Precedence (Arithmetic Operations)
Posted in C++ Source Codes | Tagged: Arithmetic, C plus plus, C++, Code, Codes, Data, Declaration, Expressions, Operations, Operator, Operators, Precedence, Source, Source Code, Source Codes, Tutorial, Tutorials, Types, Variables | Leave a Comment »
Posted by Mark Darwin on October 19, 2009
New pages are added to my blog that teaches the basic C++ tutorials. New tutorials will be added soon!
Posted in C++ Source Codes | Tagged: Basic, C plus plus, C++, cin, Code, cout, escape, Getting, Program, sequence, Source, Source Code, Source Codes, started, Structure, Tutorial, Tutorials | 1 Comment »
Posted by Mark Darwin on October 10, 2009
Program Description
This is a program that accepts date written in numerical form and displays them as a complete form. The acceptable range for years are from 0 to 9999.
Output
Input : 2 26 1986
Output : February 26, 1986
Source Code
#include <iostream>
using namespace std;
int main()
{
int month, day, year;
cout<<”Input : “;
cin>>month
>>day
>>year;
if(((((month==1 || month==3) || (month==5 || month==7)) || ((month==8 || month==10) || month==12)) && (day<=31)) && (year>0 && year<9999))
{
if(month==1)
{
cout<<”Output : “
<<”January “;
}
else if(month==3)
{
cout<<”Output : “
<<”March “;
}
else if(month==5)
{
cout<<”Output : “
<<”May “;
}
else if(month==7)
{
cout<<”Output : “
<<”July “;
}
else if(month==8)
{
cout<<”Output : “
<<”August “;
}
else if(month==10)
{
cout<<”Output : “
<<”October “;
}
else
{
cout<<”Output : “
<<”December “;
}
cout<<day<<”, “<<year<<endl;
}
else if((month==2 && day<=29) && (year>0 && year<9999))
cout<<”Output : “<<”February “<<day<<”, “<<year<<endl;
else if((((month==4 || month==6) || (month==9 || month==11)) && (day<=31)) && (year>0 && year<9999))
{
if(month==4)
{
cout<<”Output : “
<<”April “;
}
else if(month==6)
{
cout<<”Output : “
<<”June “;
}
else if(month==9)
{
cout<<”Output : “
<<”September “;
}
else if(month==11)
{
cout<<”Output : “
<<”November “;
}
cout<<day<<”, “<<year<<endl;
}
else
cout<<”Output : Invaliid date.”;
return 0;
}

Posted in C++ Source Codes | Tagged: C plus plus, C++, Code, Converter, Date, Source, Source Code, Source Codes | Leave a Comment »
Posted by Mark Darwin on October 9, 2009
Program Description
This program will ask for the total amount of grocery bill to be paid by the customer and the payment given by the customer. This will display the number if 100 peso, 50 peso, 20 peso bill, 10 peso, 5 peso, 1 peso coin should be given back to the customer.
Output
Enter total amount of grocery bill: 235
Enter amount of payment: 500
Change should be: 265
2 piece/s of 100 peso bill
1 piece/s of 50 peso bill
0 piece/s of 20 peso bill
1 piece/s of 10 peso coin
1 piece/s of 5 peso coin
0 piece/s of 1 peso coin
Source Code
#include <iostream>
using namespace std;
int main()
{
int bill, payment;
cout<<”Enter total amount of grocery bill: “;
cin>>bill;
cout<<”Enter amount of payment: “;
cin>>payment;
int change=payment-bill;
cout<<endl<<endl
<<”Change should be: “
<<change
<<endl<<endl;
int hun=change/100;
int fif=(change-(hun*100))/50;
int twen=(change-(hun*100)-(fif*50))/20;
int ten=(change-(hun*100)-(fif*50)-(twen*20))/10;
int five=(change-(hun*100)-(fif*50)-(twen*20)-(ten*10))/5;
int one=(change-(hun*100)-(fif*50)-(twen*20)-(ten*10)-(five*5))/1;
cout<<hun<<” piece/s of 100 peso bill”<<endl
<<fif<<” piece/s of 50 peso bill”<<endl
<<twen<<” piece/s of 20 peso bill”<<endl
<<ten<<” piece/s of 10 peso coin”<<endl
<<five<<” piece/s of 5 peso coin”<<endl
<<one<<” piece/s of 1 peso coin”<<endl;
return 0;
}
Posted in C++ Source Codes | Tagged: C plus plus, C++, Change, Code, Codes, Grocery, Source, Source Code, Source Codes | 1 Comment »
Posted by Mark Darwin on October 8, 2009
Program Description
Quadratic equation is an equation where the highest power of x is x2. The general form of a quadratic equation is
ax2 + bx + c = 0; where a≠ 0.
The letters a, b, and c are called coefficients: a is the quadratic coefficient of x2, b is linear coefficient of x, and c is the constant coefficient.
One of the methods to solve quadratic equation is the use of quadratic formula given below:

Here is a program that will ask for the three coefficients and will solve for the roots of x using the quadratic formula.
Output
Enter a value for coefficient a : 1
Enter a value for coefficient b : 4
Enter a value for coefficient c : 3
The roots of x are : -1 and 3
Source Code
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a, b, c;
cout<<”Enter value for coefficient a: “;
cin>>a;
cout<<”Enter value for coefficient b: “;
cin>>b;
cout<<”Enter value for coefficient c: “;
cin>>c;
double in=pow(b,2.0)-(4*a*c);
float num1=-b+sqrt(in);
float num2=-b-sqrt(in);
float x1=num1/(2*a);
float x2=num2/(2*a);
cout<<”\n \n”;
cout<<”The roots of x are: “<<x1<<” and “<<x2<<endl;
return 0;
}

Posted in C++ Source Codes | Tagged: C plus plus, C++, Code, Codes, Quadratic, Solver, Source, Source Codes | Leave a Comment »
Posted by Mark Darwin on October 7, 2009
Program Description
Here is a program that converts hours and minutes to seconds. The user will be asked to enter value for hours and minutes then the value in seconds will be displayed.
Output
Enter value for hour: 3
Enter value for minutes: 30
There are 12600 seconds in 3 hour/s and 30 minute/s.
Source Code
#include <iostream>
using namespace std;
int main()
{
int hr, min;
cout<<” Enter value for hour: “;
cin>>hr;
cout<<”\n Enter value for minutes: “;
cin>>min;
cout<<”\n \n \n”;
cout<<”There are “<<min*60+hr*3600<<” seconds in “<<hr<<” hour/s and “<<min<<” minute/s.”<<endl;
return 0;
}

Posted in C++ Source Codes | Tagged: C plus plus, C++, Code, Codes, Converter, Source, Source Code, Source Codes, Time, Time Converter | Leave a Comment »
Posted by Mark Darwin on October 6, 2009
Program Description
A place-value notation system is a numeral system in which each position is related to the next position by a constant multiplier, a common ration, called the base or radix of that numeral system. The total value of a positional number is the total of the resultant values of all positions. For example, the base-10 numeral value of 123 has 1 hundreds, 2 tens, and 3 ones. It can also be represented as:
1 x 102 + 2 x 101 + 3 x 100
Evaluating the expression will have:
(1 x 100) + (2 x 10) + (3 x 1) =123
Here is a program that will determine the place values of the input number. Accepted values will range from 0 to 9999 only.
Output
Example
Enter a number in the range 0 to 9999: 5793
5 thousands, 7 hundreds, 9 tens, and 3 ones.
Source Code
#include <iostream>
using namespace std;
int main()
{
int number;
cout<<”Enter a number in the range 0 to 9999: “;
cin>>number;
int thousands=number/1000;
int hundreds=(number/100)-thousands*10;
int tens=(number/10)-thousands*100-hundreds*10;
int ones=number/1-thousands*1000-hundreds*100-tens*10;
cout<<thousands<<” thousands, “<<hundreds<<” hundreds, “<<tens<<” tens, “<<ones<<” ones. \n”;
return 0;
}

Posted in C++ Source Codes | Tagged: C++, Code, Codes, Mark Darwin Nacionales, Place, Source, Source Code, Source Codes, Values | Leave a Comment »
Posted by Mark Darwin on October 5, 2009
Program Description
A fraction is a concept of proportional relation between an object part and the object whole. It is consist of two parts, the numerator and the denominator. The numerator represents the object part while the denominator represents the object whole. In mathematics, there are several operations we can perform with fractions such as addition, subtraction, multiplication, and division among others.
Here is a program the will add, subtract, multiply and divide fractions.
Output
Example 1
Enter value for numerator 1: 1
Enter value for denominator 1: 3
Enter value for numerator 2: 1
Enter value for denominator 2: 2
Sum is 5/6
Difference is -1/6
Product is 1/6
Quotient is 2/3
Example 2
Enter value for numerator 1: 3
Enter value for denominator 1: 4
Enter value for numerator 2: 1
Enter value for denominator 2: 5
Sum is 19/20
Difference is 11/20
Product is 3/20
Quotient is 15/4
Source Code
#include <iostream>
using namespace std;
int main()
{
int num1, num2, dem1, dem2;
//assignment of variables
cout<<” Enter value for numerator 1: “;
cin>>num1;
cout<<” Enter value for denominator 1: “;
cin>>dem1;
cout<<” Enter value for numerator 2: “;
cin>>num2;
cout<<” Enter value for denominator 2: “;
cin>>dem2;
cout<<”\n \n”;
//Formulas and Output
cout<<” Sum is “<<(num1)*(dem2)+(num2)*(dem1)<<”/”<<(dem1)*(dem2);
cout<<”\n Difference is “<<(num1)*(dem2)-(num2)*(dem1)<<”/”<<(dem1)*(dem2);
cout<<”\n Product is “<<(num1)*(num2)<<”/”<<(dem1)*(dem2);
cout<<”\n Quotient is “<<(num1)*(dem2)<<”/”<<(dem1)*(num2)<<”\n”;
return 0;
}

Posted in C++ Source Codes | Tagged: C plus plus, C++, Code, Codes, Fraction, Solver, Source | 1 Comment »