| C++ Program [Source Code] to convert Celsius to Fahrenheit
|
|
//Directory Name:C:\tc\convert.cpp
// Programmer : Ali
//Brief Description: This Program [Source Code] is used to convert Celsius to
Fahrenheit
#include <iostream.h>
#include <conio.h>
int main()
{
clrscr(); // clear the console
windows
float celsius, fahrenheit;
// declare variable of type float
cout << "Enter Celsius temperature: ";
// simple display message on screen
cin >> celsius; // get input from keyboard
fahrenheit = 1.8 * celsius + 32; // perform
calculation
cout << "Fahrenheit = " << fahrenheit << endl;
// print output to console window
getche(); //pause the output windows
return 0;
}
|
| Important Points: |
Compilation of the every program always start from top to bottom
Execution of every program starts in the main() function
The main() function is declared to return an int, therefore it must return some
integer value. Zero is commonly used to indicate that the program terminated
successfully. |
|
|
| Input - Output - Variables - Constants |
| A C++ Program [Source Code] to print some
text |
| A C++ Program [Source Code] to print some
text on two separate lines. |
| A C++ Program [Source Code] to find the
sizes, addresses of the variables of type int, float and char. |
| A C++ Program [Source Code] that reads two
numbers from user, computes and display their sum.
|
| A C++ Program [Source Code] to illustrate
the declaration, initialization and printing of a constant variable.
|
| A C++ Program [Source Code] to illustrate
the use of refrence variables
|
| Bitwise Operators |
| A C++ Program [Source Code] to show the use of
Bitwise operator (|) OR.
|
| A C++ Program [Source Code] to show the use of
Bitwise operator (&) AND
|
| A C++ Program [Source Code] to show the use of
Bitwise operator (^) XOR
|
| A C++ Program [Source Code] to show the use of
Bitwise operator (<<) LEFT SHIFT
|
| A C++ Program [Source Code] to show the use of
Bitwise operator (>>) RIGHT SHIFT.
|
| Conditional Statements |
| A C++ Program [Source Code] that reads marks obtained
by a student in a test of 100 marks and prints pass if they are grater than 50
and otherwise it prints Fail.
|
| A C++ Program [Source Code] that reads a number and
prints even if the number is even and prints odd if the number is odd.
|
| A C++ Program [Source Code] that reads marks obtained
by a student in a test of 100 marks and computes his grade according to the
following criteria. Marks >=80 grade=A Marks >=70 and < 80 grade=B
Marks >=60 and < 70 grade=C Marks >=50 and < 60 grade=D Otherwise
grade F |
| A C++ Program [Source Code] that reads marks obtained
by a student in a test of 100 marks and prints pass if they are grater than 50
and otherwise it prints Fail. [ using compact if-else ]
|
| A C++ Program [Source Code] that reads marks obtained
by a student in a test of 100 marks and computes his grade according to the
following criteria. Marks>=80 grade=A Marks>=70 & <80 grade=B
Marks>=60 & <70 grade=C Marks>=50 & <60 grade=D Otherwise
grade=F
|
| A C++ Program [Source Code] that reads two integers
and an operator, evaluates and displays the result. [ using switch-case
statements ]
|
| Loop Continue/Break Statement |
| A C++ Program [Source Code] that prints the first 10
integers. [ using for loop ]
|
| A C++ Program [Source Code] that prints odd numbers
form 0 to 50. [ Using for Loop ]
|
| A C++ Program [Source Code] that reads a number,
coumputes and displays its factorial. [ using for loop ]
|
| A C++ Program [Source Code] to print a diamond. [
using nested for loop ]
|
| A C++ Program [Source Code] that computes and display
the sum of first ten integers. [ using for loop ]
|
| A C++ Program [Source Code] that computes and display
the square of first ten integers. [ using for loop ]
|
| A C++ Program [Source Code] that prints first 20
integers. [ using while loop ]
|
| A C++ Program [Source Code] that prints first 20
integers in reverse order. [ using while loop ]
|
| A C++ Program [Source Code] that prints (a) All the
odd numbers between 0 to 50, (b) All the even numbers between 0 to 50, (c) All
the numbers that are divisible by 5 between 0 to 50. [ using while loop ]
|
| A C++ Program [Source Code] that reads a number,
coumputes and displays its factorial. [ using while loop ]
|
| A C++ Program [Source Code] that reads a number and
displays it with its digits in reverse order. [ using while loop ]
|
| A C++ Program [Source Code] that reads a number and
displays it with its digits in reverse order. [ using do-while loop ]
|
| A C++ Program [Source Code] that reads a
number,coumputes and displays its factorial. [ using do-while loop ]
|
| A C++ Program [Source Code] that prints all the even
numbers between 0 to 50. [ using while, do-while and for loop ]
|
| A C++ Program [Source Code] to illustrate the use of
the break statement.
|
| A C++ Program [Source Code] to illustrate the use of
the continue statement
|
|
A C++ program(source code) to draw pascal
triangle
1
1 1
1 2 1
1 2 2 1
1 2 3 2 1
so on...................
|
| A program(source code) in C++ to validates an
input value to lie within given bounds.Forces user to enter value until it is
within bounds |
| A C++ Programs (Source Code) (Deitel How to program
in c++ solved exercise)that do the following.Drivers are concerned with the
mileage obtained by their automobiles. One driver has kept track of several
tankfuls of gasoline by recording miles driven and gallons used for each
tankful. Develop a C++ program that will input the miles driven and gallons
used for each tankful. The program should calculate and display the miles per
gallon obtained for each tankful. After processing all input information, the
program should calculate and print the combined miles per gallon obtained for
all tankfuls |
Develop a C++ program (Source Code )(Deitel How to
program in c++ solved exercise)that will determine if a department store
customer has exceeded the credit limit on a charge account. For each customer,
the following facts are available:
a) Account number (an integer)
b) Balance at the beginning of the month
c) Total of all items charged by this customer this month
d) Total of all credits applied to this customer's account this month
e) Allowed credit limit The program should input each of these facts, calculate
the new balance (= beginning balance + charges – credits) and determine if the
new balance exceeds the customer's credit limit. For those customers whose
credit limit is exceeded, the program should display the customer's account
number, credit limit, new balance and the message “Credit limit exceeded”. |
| (Deitel How to program in c++ solved exercise)One
large chemical company pays its salespeople on a commission basis. The
salespeople receive $200 per week plus 9 percent of their gross sales for that
week. For example, a salesperson who sells $5000 worth of chemicals in a week
receives $200 plus 9 percent of $5000, or a total of $650. Develop a C++
program that will input each salesperson's gross sales for last week and
calculate and display that salesperson's earnings. Process one salesperson's
figures at a time. |
| Develop a C++ program (Deitel How to program in c++
solved exercise)that will determine the gross pay for each of several
employees. The company pays “straight-time” for the first 40 hours worked by
each employee and pays “time-and-a-half” for all hours worked in excess of 40
hours. You are given a list of the employees of the company, the number of
hours each employee worked last week and the hourly rate of each employee. Your
program should input this information for each employee and should determine
and display the employee's gross pay. |
| The process of finding the largest number (i.e., the
maximum of a group of numbers) is used frequently in computer applications. For
example, a program that determines the winner of a sales contest would input
the number of units sold by each salesperson. The salesperson who sells the
most units wins the contest. Write a pseudocode program(Deitel How to program
in c++ solved exercise), then a C++ program that inputs a series of 10 numbers,
and determines and prints the largest of the numbers. |
| The process of finding the largest number (i.e., the
maximum of a group of numbers) is used frequently in computer applications. For
example, a program that determines the winner of a sales contest would input
the number of units sold by each salesperson. The salesperson who sells the
most units wins the contest. Write a pseudocode program,(Deitel How to program
in c++ solved exercise) then a C++ program that inputs a series of 10 numbers,
and determines and prints the two largest of the numbers. |
Write a C++ program(Deitel How to program in c++
solved exercise) that utilizes looping and the tab escape sequence \t to print
the following table of values:
N 10*N
100*N 1000*N
1 10
100 1000
2
20 200
2000
3
30
300 3000
4
40
400 4000
5
50
500 5000
|
Write a in C++ program(Source Code) (Deitel How to program in c++
solved exercise)that reads in the size of the side of a square and then prints
a hollow square of that size out of asterisks and blanks. Your program should
work for squares of all side sizes between 1 and 20. For example, if your
program reads a size of 5, it should print
*****
* *
* *
* *
*****
|
| A palindrome is a number or a text phrase that reads
the same backwards as forwards. For example, each of the following five-digit
integers is a palindrome: 12321, 55555, 45554 and 11611. Write a
program (Deitel How to program in c++ solved exercise) in C/C++ that reads
in a five-digit integer and determines whether it is a palindrome.
|
| (Deitel How to program in c++ solved exercise)Input
an integer containing only 0s and 1s (i.e., a “binary” integer) and print its
decimal equivalent. (Hint: Use the modulus and division operators to pick off
the “binary” number’s digits one at a time from right to left. Just as in the
decimal number system where the rightmost digit has a positional value of 1 and
the next digit left has a positional value of 10, then 100, then 1000, etc., in
the binary number system, the rightmost digit has a positional value of 1, the
next digit left has a positional value of 2, then 4, then 8, etc. Thus the
decimal number 234 can be interpreted as 4 * 1 + 3 * 10 + 2 * 100. The decimal
equivalent of binary 1101 is 1 * 1 + 0 * 2 + 1 * 4 + 1 * 8 or 1 + 0 + 4 + 8, or
13.) |
| Write a in C/C++program(Deitel How to program in c++
solved exercise) that reads three nonzero double values and determines and
prints if they could represent the sides of a right triangle. |
| A company wants to transmit data over the telephone,
but they are concerned that their phones may be tapped. All of their data are
transmitted as four-digit integers. They have asked you to write a program that
encrypts their data so that it can be transmitted more securely. Your program
should read a four-digit integer and encrypt it as follows: Replace each digit
by (the sum of that digit plus 7) modulus 10. Then, swap the first digit with
the third, swap the second digit with the fourth and print the encrypted
integer. Write a separate program (Deitel How to program in c++ solved
exercise)in C/C++ that inputs an encrypted four-digit integer and decrypts
it to form the original number. |
|
Write a program that displays the following
checkerboard pattern
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * * *
|
| Write a program in c/c++ Deitel How to program in
c++ solved exercise that reads the radius of a circle (as a double value) and
computes and prints the diameter, the circumference and the area. Use the value
3.14159 for pi. |
|
Write a program that prints the following patterns
separately one below the other. Use for loops to generate the patterns. All
asterisks (*) should be printed by a single statement of the form cout <<
'*'; (this causes the asterisks to print side by side). Hint: The last two
patterns require that each line begin with an appropriate number of blanks.
Extra credit: Combine your code from the four separate problems into a single
program that prints all four patterns side by side by making clever use of
nested for loops.
* * *
* * * * * * * * * * * * * * * *
*
*
*
*
*
* * * * * * * *
*
* * * * * * * *
*
* *
* *
*
* * * * * * *
*
* * * * * * *
*
* * *
* * *
*
* * * * * *
*
* * * * * *
* *
* * *
* * * *
*
* * * * *
*
* * * * *
* *
* * * *
* * * * *
*
* * * *
* *
* * *
*
* * * * * *
* * * * * *
*
* * *
* *
* *
* *
* * * * * *
* * * * * * *
*
* *
*
* * * * * * *
* * * *
* * * * * * * *
* *
*
* * * * * * * * * * *
* * * * * * * * *
*
* *
* * * * * * * * * *
|
| One interesting application of computers is drawing
graphs and bar charts (sometimes called “histograms”). Write a program in C++
that reads five numbers (each between 1 and 30). For each number read, your
program should print a line containing that number of adjacent asterisks. For
example, if your program reads the number seven, it should print *******. |
A mail order house sells five different products
whose retail prices are product 1 — $2.98, product 2—$4.50, product 3— $9.98,
product 4—$4.49 and product 5—$6.87. Write a program that reads a series of
pairs of numbers as follows:
a) Product number
b) Quantity sold for one day Your program should use a switch statement to help
determine the retail price for each product. Your program should calculate and
display the total retail value of all products sold last week. |
| Write a program in C/C++ that prints a table of the
binary, octal and hexadecimal equivalents of the decimal numbers in the range 1
through 256.
|
Calculate the value of p from the infinite
series Print a table that shows the value
of p approximated by 1 term of this series, by two terms, by three terms, etc.
How many terms of this series do you have to use before you first get 3.14?
3.141? 3.1415? 3.14159? |
| Pythagorean Triples) A right triangle can have sides
that are all integers. The set of three integer values for the sides of a right
triangle is called a Pythagorean triple. These three sides must satisfy the
relationship that the sum of the squares of two of the sides is equal to the
square of the hypotenuse. Find all Pythagorean triples for side1, side2 and
hypotenuse all no larger than 500. Use a triple-nested for-loop that tries all
possibilities. This is an example of “brute force” computing. You will learn in
more advanced computer science courses that there are many interesting problems
for which there is no known algorithmic approach other than using sheer brute
force. |
| A company pays its employees as
managers (who receive a fixed weekly salary), hourly workers (who receive a
fixed hourly wage for up to the first 40 hours they work and “time-and-a-half,”
i.e., 1.5 times their hourly wage, for overtime hours worked), commission
workers (who receive $250 plus 5.7% of their gross weekly sales), or
pieceworkers (who receive a fixed amount of money per item for each of the
items they produce—each pieceworker in this company works on only one type of
item). Write a program to compute the weekly pay for each employee. You do not
know the number of employees in advance. Each type of employee has its own pay
code: Managers have paycode 1, hourly workers have code 2, commission workers
have code 3 and pieceworkers have code 4. Use a switch to compute each
employee’s pay based on that employee’s paycode. Within the switch, prompt the
user (i.e., the payroll clerk) to enter the appropriate facts your program
needs to calculate each employee’s pay based on that employee’s paycode. |
|
Write a program in C/C++ that prints the
following diamond shape. You may use output statements that print either a
single asterisk (*) or a single blank. Maximize your use of repetition (with
nested for structures) and minimize the number of output statements.
*
* * *
* * *
* *
*
* * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
|
|