C++ programs and output:-
Program 1 - Numerology This C++ program prompts for birth date and outputs planet for that date.
In the above screen shot, user has entered number 23, that is, birth date is 23, which belongs to Planet MercuryIn the above screen shot, user has entered ooo, which is not a number, so it says 0 No numerology or planet for you...
#include <iostream>
using namespace std;
//Numerology
int main(){
int a;
int b;
cout << "Enter your Birth date: ";
cin >> a;
cout << "Your Birth date: " << a << "\n";
if (a == 1 || a == 10 || a == 19 || a == 28)
{
cout << "You have born on: " << a << " Your planet is SUN " << "\n";
}
else if (a == 2 || a == 11 || a == 20 || a == 29)
{
cout << "You have born on: " << a << " Your planet is MOON " << "\n";
}
else if (a == 3 || a == 12 || a == 21 || a == 30)
{
cout << "You have born on: " << a << " Your planet is JUPITER " << "\n";
}
else if (a == 4 || a == 13 || a == 22 || a == 31)
{
cout << "You have born on: " << a << " Your planet is RAHU " << "\n";
}
else if (a == 5 || a == 14 || a == 23)
{
cout << "You have born on: " << a << " Your planet is MERCURY" << "\n";
}
else if (a == 6 || a == 15 || a == 24)
{
cout << "You have born on: " << a << " Your planet is VENUS" << "\n";
}
else if (a == 7 || a == 16 || a == 25)
{
cout << "You have born on: " << a << " Your planet is KETHU" << "\n";
}
else if (a == 8 || a == 17 || a == 26)
{
cout << "You have born on: " << a << " Your planet is SATURN" << "\n";
}
else if (a == 9 || a == 18 || a == 27)
{
cout << "You have born on: " << a << " Your planet is MARS" << "\n";
}
else if ( a != 1, 10, 19, 28, 2, 11, 20, 29, 3, 12, 21, 30, 4, 13, 22, 31, 5, 14, 23, 6, 15, 24, 7, 16, 25, 8, 17, 26, 9, 18, 27)
{
cout << "Not a BIRTH number: " << a << " No numerology or planet for you..." << "\n";
}
else
{
cout << "You have born on: " << a << " No numerology or planet for you...";
}
return 0;
}
Good morning friends! Wishing you all a beautiful day...
1500 Plus Greeting wish pics / Images
Program 1a
#include <iostream>
using namespace std;
int main()
{
int ingredienta = 10;
int ingredientb = 20;
int ingredientc = 30;
int N; //number of ingredients
int iq1, iq2, iq3, iq4; //ingredient quantity
int sum;
float average;
cout << "Enter number of ingredients: ";
cin >> N;
cout << "You have entered ingredients: " << N << "\n";
cout << "Enter four quantity of ingredients: ";
cin >> iq1;
cin >> iq2;
cin >> iq3;
cin >> iq4;
sum = iq1 + iq2 + iq3 + iq4;
average = sum/N;
cout << "Total Puff girls is =" << sum << "\n";
cout << "Average Puff girls are =" << average << "\n";
return 0;
}
Program 2 - Print alphabets a to z in lowercase letters
#include <iostream>
using namespace std;
int main(){
char ch = 'a';
do
{
cout << ch << ' ';
ch++;
} while (ch <= 'z' );
return 0;
}
Below is output screenshot
***********************************************************************Hi friends,
First of all I thank the Management and Staff of gorgeous Google for this wonderful web space. I have been practicing few C++ programs, same I will be posting in this blog with the output screen shots. THE MAIN PURPOSE OF ALL MY BLOGS ARE FOR POPULARIZING SOFTWARE COMPANIES, THEIR PRODUCTS AND SERVICES. Of course, jobs for the job seekers. In this blog itself, you will find links to Web Design, Graphic Design, Android / IOS App Development, E-Commerce, SEO, Digital Marketing Companies in India, Gulf and USA.
Best regards,
Srinivasan B alias Raja
************************************************************************
Program 3 Printing addresses of the short and long variables
#include <iostream>
using namespace std;
int main()
{
unsigned short shortVar=5;
unsigned long longVar=65535;
long sVar = -65535;
cout << "shortVar: \t" << shortVar;
cout << " Address of shortVar:\t";
cout << &shortVar << "\n";
cout << "longVar:\t" << longVar;
cout << " Address of longVar:\t" ;
cout << &longVar << "\n";
cout << "sVar:\t" << sVar;
cout << " Address of sVar:\t" ;
cout << &sVar << "\n";
return 0;
}
OUTPUT SCREEN SHOT OF ABOVE C++ PROGRAM IS BELOW.
Program 4 - three integer variables are declared a, b and c. Value of number 5 is assigned to variable b. Input is accepted for variable c on run time, accordingly output is printed on the screen after addition, minus of c variable.
#include <iostream>
using namespace std;
int main(){
int a = 5;
int b(5);
int c;
int total;
int total1;
c = a + b;
cout << "Enter the value of c: ";
cin >> c;
total = a + b + c;
cout << "Total of a, b and c is: " << total << endl;
total1 = total - b;
cout << "value of total1 is: "<< total1;
return 0;
}
BELOW IS THE OUTPUT SCREEN SHOT OF THE ABOVE PROGRAM
Program 4 - this C++ program prompts for inputting text and outputs the number of (count) characters on the screen
#include <iostream>
using namespace std;
int main() {
int count = 0;
char c;
cout << "Input Text\n";
cin.get(c);
while (c != '\n')
{
cout.put(c);
count++;
cin.get(c);
}
cout << "\nNumber of characters = " << count << "\n";
return 0;
}
Program 5 - this program prompts for the positive integer number and output backs factorial of that number.
#include <iostream>
#include <conio.h>
using namespace std;
long fact (int n)
{
if (n == 0) //base case
return 1;
return (n * fact (n-1) );
}
int main()
{
int num;
cout << "Enter a positive integer: ";
cin >> num;
cout << "Factorial of " << num << " is " << fact(num);
getch();
return 0;
}
Output screen shot of above C++ program is given below
Program 6 - this program accepts, pre-inputted float variables of x and y for multiplying. Also double variables of p and q for division purpose. Accordingly outputs multiplied and divided numbers.
#include<iostream>
using namespace std; //inline functions
inline float mul(float x, float y)
{
return(x*y);
}
inline double div(double p, double q)
{
return(p/q);
}
int main()
{
float a = 15.345;
float b = 3.02;
cout << mul(a,b) << "\n";
cout << div(a,b) << "\n";
return 0;
}
Output Screen Shot of above C++ program is displayed below:-
Program 7 - this program accepts the integer values and print back in words.
#include <iostream>
using namespace std;
int main() {
long int n, sum=0, r;
cout << "Enter the number:";
cout << endl;
cin >> n;
while (n>0)
{
r=n%10;
sum = sum*10+r;
n = n/10;
}
n = sum;
while (n>0)
{
r = n%10;
switch(r)
{
case 1:
cout << "one";
break;
case 2:
cout << "two";
break;
case 3:
cout << "three";
break;
case 4:
cout << "four";
break;
case 5:
cout << "five";
break;
case 6:
cout << "six";
break;
case 7:
cout << "seven";
break;
case 8:
cout << "eight";
break;
case 9:
cout << "nine";
break;
case 0:
cout << "zero";
break;
default:
cout << "tttt";
break;
}
n = n/10;
}
}
Output screen shot of the above C++ program is displayed below.
Program 8 - this programs computes the Square root of inputted number.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x1, x2, x3;
cout << "\n Number \t Square Root" << endl;
cout << "\n " << x1 << " \t " << sqrt(x1) << endl;
cout << "\nType a number whose square root is to be"
" computed. ";
cin >> x1;
cout << "Number entered is : " << x1 << endl;
cout << "Square root of inputted number is " << sqrt(x1) << endl;
return 0;
}
Output screen shot of the above program is displayed below:-
Program 9 - This C PLUS PLUS Program accepts your name or some text, count the number of characters and display back the same along with the entered text, name with greeting "Have a Good Day!" on the screen.
#include <iostream>
#include <string> //Declaration of class string
using namespace std;
int main()
{
//Defines four strings
string prompt("Enter your name: "),
name, //an empty
line ( 40, '-'), // sting with 40 '-'
total = "Hello ";
cout << prompt; // Request for input
getline(cin, name); // Inputs a name in one line
total = total + name; // Concatenates and assigns strings
cout << line << endl // Outputs line and name.
<< total << endl;
cout << "Your name is " // Outputs length
<< name.length() <<" " << "Characters long!" << endl;
cout << "Have a Good Day!" << " " << name << endl;
cout << line << endl;
return 0;
}
 |
| The pessimist sees difficulty in every opportunity; an optimist sees the opportunity in every difficulty. Life motivational quote by -Winston Churchill |
 |
Whatever you are, be a good one. - Abraham Lincoln. Great work is done by people, who are not afraid to be great. - Fernando Flores. If God shuts one door, another door opens. - Irish Proverb
Problem 10- Try catch Block throwing an Exception
#include <iostream> using namespace std;
int main(){ int number1, number2; cout << "Enter the value of Number 1 and Number 2 \n"; cin >> number1; cin >> number2; int number3 = number1 - number2; cout << "number1 MINUS number2: that is number 3 is: " << number1-number2 << "\n"; try { if(number1 != 0) { cout << "Result (number1 / number3) = "<< number1 / number3 << "\n"; } else // Divide by Zero Exception { throw(number3); // Throw Integer Object } } catch(int i) //Catches the Exception { cout << "Exception Caught: Divide By ZERO" << "\n"; } cout << "END"; return 0; }
Below is the output screen shot.
In the above screen shot value of number 1 is 50 and value of number 2 is 25. Number 1 minus Number 2 is 25. Number 50 (Number 1) divided by 25 is 2
In the above screen shot DIVIDE BY ZERO EXCEPTION ERROR. THAT IS 50 Divided by 0
|
Comments
Post a Comment