This document provides a manual with 65 questions on C++ programming concepts and formulas. It covers topics like input/output, data types, operators, conditional statements, loops, functions, arrays, pointers, structures, file handling and classes. For each question, it provides the problem statement, sample code and explanation. The questions range from basic programs to calculate area, swap values, find remainder to advanced programs involving formulas, date calculations and currency conversions. It is intended to help students of 2nd and 3rd year learn and practice C++ programming.
Industrial Training Report- AKTU Industrial Training Report
Input output
1. Manual # 1
Topic:
Use of Formula`s
Input & Output
Subject:
C & C++
Classes:
2nd
Year & 3rd
Year
Author:
Sunawar Khan Ahsan
MS(Computer Vision)
Author2:
Mehwish Shabbir
2. ---------------------------------------------------------------------------------
Q#1:Write a program, which will display your name.
---------------------------------------------------------------------------------
Q # 2: Execute the following formula`s in C++:
Use of Addition, Subtraction, Multiplication & Division
Addition: cout<<4+2<<"n";
Subtraction: cout<<2-6<<”n”;
Multiplication: cout<<3*8<<”n”;
Division: cout<<6/3<<”n”;
For Formula below, you have to include the header file: math.h (#include<math.h>)
Absolute: cout<<abs(-8)<<”n” ;means that it will give modulus of value given i.e. +ive
value
Exponent: cout<<exp(6)<<”n”;
Power: cout<<pow(2,9)<<"n"; means that 2 raise to power 9 i.e. 2^9.
Square Root: cout<<sqrt(16)<<”n”;
Logarithm & Trigonometric Functions:
Natural Algorithum: cout<<log(3)<<”n”; Gives the natural logarithm of 3.
Sine: cout<<sin(45)<<”n”; Gives the Sine value of 45 degrees in radians.
Cosine: cout<<cos(45)<<”n”; Gives the cosine value of 45 degrees in radians.
Tangent: cout<<sin(45)<<”n”; Gives the Tangent value of 45 degrees in radians.
Inverse of Sine: cout<<asin(30)<<”n”;Gives the inverse sine of 30 degrees in radians.
Inverse of Cosine: cout<<acos(30)<<”n”;Gives the inverse cosine of 30 degrees in
radians.
Inverse of Tangent: cout<<atan(30)<<”n”;Gives the inverse tangent of 30 degrees in
radians.
Hyperbolic Sine: cout<<sinh(60)<<”n”; Gives the hyperbolic sine of 60 degrees
in radians.
Hyperbolic Cosine: cout<<cosh(60)<<”n”; Gives the hyperbolic cosine of 60 degrees
in radians.
Hyperbolic Tangent: cout<<tanh(60)<<”n”; Gives the hyperbolic tangent of 60 degrees
in radians.
------------------------------------------------------------------------------------------------------------
1. Declarationof Variable of Data Type (Integer)
(a). Assigning a Fixed Value to Variable
#include <iostream.h>
int main()
{
int length;
length = 7;
cout<<"The Length is: ";
cout<<length;
cout<<"nn";
return 0;
}
(b). Assign the Value to Variable through Keyboard
Remember to take value from keyboard, we use cin with operator >>.
#include <iostream.h>
3. int main()
{
int length;
cin>>length;
cout<<"The Length is: ";
cout<<length;
cout<<"nn";
return 0;
}
2. Calculate the Area of the Box
#include <iostream.h>
int main()
{
int length;
int width;
length=7;
width=5;
cout<<"The area is: ";
cout<<length*width;
cout<<"nn";
return 0;
}
// The above program can also be written as:
#include <iostream.h>
int main()
{
int length, width, area; //you can declare the variable in one line.
length=7;
width=5;
area = length * width; //you can store the result of multiplication in another
//variable
cout<<"The area is: ";
cout<<area;
cout<<"nn";
return 0;
}
// Program should take the value of length and width from User
#include <iostream.h>
int main()
{
4. int length, width, area; //you can declare the variable in one line.
cin>>length;
cin>>width;
area = length * width;
cout<<"The area is: ";
cout<<area;
cout<<"nn";
return 0;
}
// You can take the value from User in one line as Well.
#include <iostream.h>
int main()
{
int length, width, area; //you can declare the variable in one line.
cin>>length>>width;
area = length * width;
cout<<"The area is: ";
cout<<area;
cout<<"nn";
return 0;
}
// Now, from here on you should write your program in such a way, that it will give
the proper information.
#include <iostream.h>
int main()
{
int length, width, area; //you can declare the variable in one line.
cout<<"Enter the Length: ";
cin>>length;
cout<<"Enter the Width: ";
cin>>width;
area = length * width;
cout<<"The area is: ";
cout<<area;
cout<<"nn";
return 0;
}
------------------------------------------------------------------------------------------------------------
Q1: Write a program which will calculate the Volume of the Box. The program should be
able to take values of length, width and height of the box from the user and then display
the result.
------------------------------------------------------------------------------------------------------------
5. DeclarationofVariable of Data Type (Float)
What is the difference of float data type from integer data type??
#include <iostream.h>
int main()
{
int a, b, c;
a=10;
b=3;
c=a/b;
cout<<"Answer is: ";
cout<<c;
cout<<"nn";
return 0;
}
// The output of this program is 3, but actually 10/3 = 3.33333, but whenever fraction
comes the int variable always takes the lower value like 10/6=1.66667 but the int variable
will not convert it to 2 it will take the lower value i.e. 1 and excludes the fraction.
So, for that the variable can be declared with float.
#include <iostream.h>
int main()
{
float a, b, c;
a=10;
b=3;
c=a/b;
cout<<"Answer is: ";
cout<<c;
cout<<"nn";
return 0;
}
//Answer is 3.3333, the float variable will show the result upto five decimals places.
------------------------------------------------------------------------------------------------------------
Q2: Write a program which will convert the feet into meters. The program should be able
to take the feet value from the user and then converts it into meter.
Forumla is: meters = feet / 3.28
------------------------------------------------------------------------------------------------------------
Q3: Write a program which will calculate the value a from the following formulae:
a = p ( 1 + k)^r, where k = 10% of p.
Enter the value of p and r from the user.
------------------------------------------------------------------------------------------------------ -----
Casting: (Leave it: We`ill Discuss it Later)
#include <iostream.h>
int main()
{
int a, b, c;
a=10;
b=3;
c=a/b;
cout<<"Answer is: ";
cout<<(float) c;
cout<<"n";
6. cout<<"Answer is: ";
cout<<(float) a/b;
cout<<"nn";
return 0;
}
------------------------------------------------------------------------------------------------------------
Q4: Write a program for the calculation of the roots of Quardatic Equation. The program
should be designed in such a way that user should be able to enter the values of a, b, & c.
And the formula to calculate the roots of Quadratic Equation.
------------------------------------------------------------------------------------------------------------
Q5:If a five digit number enter is input through keyboard. Write a program to calculate
the sum of its digits.
------------------------------------------------------------------------------------------------------------
Q6:If a five digit number enter is input through keyboard. Write a program to find its
reverse.
------------------------------------------------------------------------------------------------------------
Q7:If a four digit number enters through the keyboard. Write a program to obtain sum of
the first and last digit of that number.
------------------------------------------------------------------------------------------------------------
Q8:in a town percentage of man is 52. The percentage of total literacy is 48. If total
percentage of literate men is 35 of the total population to find the total number of
illiterate men and women if the population of the town is 80,000.
------------------------------------------------------------------------------------------------------------
Q9:if the total selling price of 15 items and total profit earned on item is input through
keyboards. Write a program to find the cost price of one item.
------------------------------------------------------------------------------------------------------------
Q10: One large chemical company pays its salesperson on a commission basis. The
company pays salesman $200 per week plus 9 percent of his gross sale of that week.
For example, a salesperson sales $5000 worth of chemicals in a week, so company
pays him $200 + 9% of $5000 = $650.
Write a program for the company which will take the value from the user of total
worth in dollars sailed by the salesperson in one week and calculate his total earning of
that week.
------------------------------------------------------------------------------------------------------------
Q11: A company pays Rs: 10,000 per month to its employee. If he worked extra hours
then the company paid Rs 35 for each extra hour.
Write a program which will take the total number of extra hours of a month from the
user and then calculate the total earning of an employee of that month.
Q12:Write a program that generates the following output:
10
20
19
Use an integer constant for the 10, an arithmetic assignment operator to generate 20, and
a decrement operator to generate 19
------------------------------------------------------------------------------------------------------------
Q13: Write a program to get current year and birth year of a person and display current
age.
Q14:Write a program to convert 2.5 miles into kilometers and print the result on the
screen.
Hint: 1 mile= 1.609 Kilometer
-----------------------------------------------------------------------------------------------------------
Q15:Write a program to interchange the values of two variable using
-----------------------------------------------------------------------------------------------------------
Q16: Write a program to separate the integral and fractional parts of given real number
and print the result on the screen.
-----------------------------------------------------------------------------------------------------------
Q17:Write a program that input a character and display its ASCII code.
-----------------------------------------------------------------------------------------------------------
Q18: Write a program that input ASCII code between (0-255) and display corresponding
character against given value.
7. -----------------------------------------------------------------------------------------------------------
Q19: Write a program to calculate simple interest. It input principle amount, rate of
interest, and the number of years and display the simple interest.
Hint: i= (p*r*t)/100
------------------------------------------------------------------------------------------------------------
Q20:Write a program that input dividend and divisor it then calculate and display
quotient and remainder.
-----------------------------------------------------------------------------------------------------------
Q21:Write a program that input the distance travelled and the speed of vehicle. It
calculates time required to reach destination and display it.
-----------------------------------------------------------------------------------------------------------
Q22:The distance between two cities (K.M.) is input through keyboard. Write a program
to convert and print this distance in meters, feet and centimeters.
-----------------------------------------------------------------------------------------------------------
Q23:Write a program that input time in seconds and convert it into hh-mm-ss format.
-----------------------------------------------------------------------------------------------------------
Q24: Write a program that inputs three digit number from the user and display following
Output:
Enter Three Digit Number 456
Number Enter by the User Is 456
Number in Reverse Order Is 654
Number Display in Separate Line
4
5
6
-----------------------------------------------------------------------------------------------------------
Q25: Write a program that will prompt the user to enter number of hours it computes and
display the number of weeks, days.
-----------------------------------------------------------------------------------------------------------
Q26: Write a program that prompt age in years and display it in months, days and weeks.
-----------------------------------------------------------------------------------------------------------
Q27: Write a program that prompt marks obtained by a student in five subjects. It then
calculates and then displays the total marks and percentage.
-----------------------------------------------------------------------------------------------------------
Q28:Write a program that input basic salary and calculate 35% dearness allowance, 33.3
house rent and then display the gross salary.
-----------------------------------------------------------------------------------------------------------
Q29:Write a program that input five digit numbers and calculate its sum, average and
product.
-----------------------------------------------------------------------------------------------------------
Q30:Write a program that input two times in hh-mm-ss format, add both time and then
displays total time.
-----------------------------------------------------------------------------------------------------------
Q31:Write a program that input the X, Y co-ordinates for two points and compute the
distance between two points.
Hint: √( 𝒙𝟐 − 𝒙𝟏) 𝟐 + (𝒚𝟐 − 𝒚𝟏)𝟐
-----------------------------------------------------------------------------------------------------------
Q32:Write a program that find out the area of triangle when three sides a,b and c of the
triangle are given.
Hint: √ 𝒔( 𝒔 − 𝒂)( 𝒔 − 𝒃)(𝒔 − 𝒄) where c=a+b+c/2
-----------------------------------------------------------------------------------------------------------
Q33:Write a program that input temperature from the user in Fahrenheit and convert it
into Celsius using formula c=5/9(f-32).
-----------------------------------------------------------------------------------------------------------
Q34:Write a program that input temperature from the user in Celsius and convert it into
Fahrenheit using formula f=9/5(c+32).
-----------------------------------------------------------------------------------------------------------
Q35:Write a program that input total number of student in a class and fee per student it
displays total fee collection from class.
-----------------------------------------------------------------------------------------------------------
Q36:A car can travel 5.3 miles in 1 liter. Write a program that input petrol in liter and
display total distance cover by car.
8. -----------------------------------------------------------------------------------------------------------
Q37:Write a program to calculate volume (V) of a cube using formula
V=length*width*height.
-----------------------------------------------------------------------------------------------------------
Q38:Write a program that input a number and compute its square and cube.
-----------------------------------------------------------------------------------------------------------
Q39:Write a program that input total pages of a book, number of pages a person read in
one day and number of days a person has read the book. It displays number of pages that
have been read and number of pages remaining.
-----------------------------------------------------------------------------------------------------------
Q40:Write a program that input radius of sphere from the user calculate its volume and
area using formula 𝐴 = 4𝜋𝑟2
and 𝐶 = 4/3𝜋𝑟3
-----------------------------------------------------------------------------------------------------------
Q41: Write a program that displays following statement
The character ‘x’
The name S.K.Ahsan
The number 786
-----------------------------------------------------------------------------------------------------------
Q 42: K.E. 1/2m.v2
-----------------------------------------------------------------------------------------------------------
Q 43: S=vit+1/2at2
-----------------------------------------------------------------------------------------------------------
Q 44: vf=vi+at
-----------------------------------------------------------------------------------------------------------
Q 45: K.E. 1/2m.v2
-----------------------------------------------------------------------------------------------------------
Q 46: a=vf-vi/t
-----------------------------------------------------------------------------------------------------------
Q 48: v=d/t , d=vt
-----------------------------------------------------------------------------------------------------------
Q 49: A cashier has currency notes of denominations 10, 50,100. If the amount to be
withdrawn is input through the keyboard. Find the total number of currency notes of each
denominations the cashier will have give to the withdrawer.
-----------------------------------------------------------------------------------------------------------
Q50:Write a program to calculate the Units of demand will be demanded if the price is
Rs. 18.00? The formula p = 90(5)-q/10 applies to the demand of a product, where “q” is
the number of units and “p” is the price of one unit.
-----------------------------------------------------------------------------------------------------------
Q51:Write a program to calculate the values of l& m. If the expression lx3+ mx2 + 4
leaves the remainder of -3 and 12 when divided by (x - 1) & (x + 2) respectively.
-----------------------------------------------------------------------------------------------------------
Q52:Write a program that print the double of a number of a number that is entered by a
user. For example if user enter 702 than its calculated double number is 1404.
-----------------------------------------------------------------------------------------------------------
Q53:Write a program which shows the output as follow:
What's your name? Sunawar Khan Ahsan
Hello Sunawar Khan Ahsan.
What is your favorite team? The Isotopes
I like The Isotopes too!
-----------------------------------------------------------------------------------------------------------
Q54:Write a program to find the Length of AD& Area of ABC Of the isosceles , the
base BC = 28 cm, and AB = AC = 50 cm, If AD| BC.
-----------------------------------------------------------------------------------------------------------
Q56: Write a program that separate a string into letters/alphabets, such as input string is
Hello, and separated string is:[H][e][l][l][o][!]
-----------------------------------------------------------------------------------------------------------
Q57: Write a program to prove the Right Distributive Law Of the Production by using
dynamic input.
-----------------------------------------------------------------------------------------------------------
9. -----------------------------------------------------------------------------------------------------------
Q58:Write a program that convert the entered choice into vice versa into hexadecimal
number, octal & integer. For example if user enter 18 then this number is converted into
hexa or octal number system.
-----------------------------------------------------------------------------------------------------------
Q60:Write a program that swap the entered number without using third variable.
-----------------------------------------------------------------------------------------------------------
Q61: Write a program which accepts amount as integer and display total number of
Notes of Rs. 500, 100, 50, 20, 10, 5 and 1.For example, when user enter a number, 575,
the results would be like this...
500: 1
100: 0
50: 1
20: 1
10: 0
5: 1
1: 0
-----------------------------------------------------------------------------------------------------------
Q62: Write a program which accepts a character and display its next character.
-----------------------------------------------------------------------------------------------------------
Q63: What is the Output of following:
int result = 4 + 5 * 6 + 2;
cout<<result;
int a = 5 + 7 % 2;
cout<<a;
-----------------------------------------------------------------------------------------------------------
Q64: Write a program which accepts days as integer and display total number of years,
months and days in it.
-----------------------------------------------------------------------------------------------------------
Q65:What is the output of following:
-----------------------------------------------------------------------------------------------------------
int x = 10,y;
y = x++;
cout<<y;
int x = 10,y;
y = x++;
cout<<x;
int x = 10;
x++;
cout<<x;
int x = 10,y;
y = ++x;
cout<<y;
int x = 10;
cout<<++x;
int x = 10;
cout<<x++;
Q66:What is the output of the following?
main(){
int count=10;
cout<<"count="<<count<<endl;
cout<<"count="<<count++<<endl;
cout<<"count="<<count<<endl;
cout<<"count="<<++count<<endl;
return 0;
}
main(){
int count=10;
cout<<"count="<<count<<endl;
cout<<"count="<<count--<<endl;
cout<<"count="<<count<<endl;
cout<<"count="<<--count<<endl;
return 0;
}
int main(){
int ans=27;
ans+=10;
cout<<ans<<",";
ans-=7;
cout<<ans<<",";
ans*=2;
cout<<ans<<",";
ans/=3;
cout<<ans<<",";
ans%=3;
return 0;
}
int main(){
int i=2, j=3, k,i;
float a,b;
k=i/j*j;
i=j/j*i;
a=i/j*j;
b=j/i*i;
return 0;
}
10. Q67:What is the output of following program?
int x = 10;
cout<<x<<x++;
int x = 10;
cout<<++x<<x++<<x;
int x = 10;
cout<<x++<<x<<++x;
int x = 10,y;
y = x + x++;
cout<<y;
int x = 10,y;
y = ++x + x++ + x;
cout<<y;
int x = 10,y;
y = x++ + x + ++x;
cout<<y;
-----------------------------------------------------------------------------------------------------------
Q68: Write a program that takes length as input in feet and inches. The program should
then convert the lengths in centimeters and display it on screen. Assume that the given
lengths in feet and inches are integers.
/********************************************************
Purpose :This program converts measurement in feet and inches into centimeters.
@Author :Sunawar Khan Ahsan
********************************************************/
#include <iostream.h> //Header file
const double CENTIMETERS_PER_INCH = 2.54; //Named constants
const int INCHES_PER_FOOT = 12; //Named constants
int main ()
{
int feet, inches;
int totalInches;
double centimeter;
cout<< "Enter two integers, one for feet and one for inches: ";
cin>> feet>> inches;
cout<< endl;
cout<< "The numbers you entered are " << feet<< " for feet and " << inches<< "
for inches. " << endl;
totalInches = INCHES_PER_FOOT * feet + inches;
cout<< "The total number of inches = " << totalInches<< endl;
centimeter = CENTIMETERS_PER_INCH * totalInches;
cout<< "The number of centimeters = " << centimeter<< endl;
return 0;
}
-----------------------------------------------------------------------------------------------------------
11. Summary:
A function named main () is always the first one executed when a program is
executed.
Expression is combination of Operator and Operand e.g. sum=a+b
Output is handled by printf and input is handled by scanf object in C.
Output is handled by cout and input is handled by cin object in C++.
The variable is no longer a variable but a constant.
A function body is delimited by {}.
A function name must be followed by parenthesis otherwise compiler read it as
variable.
The three primary constants and variable types in c are integer, float and character
A variable name can be of maximum 31 characters.
Don’t use keyword as variable.
A C++ compiler produces code that can be directly executed by the computer.
A header contains information used by the program.
<iostream>,<stdio> is the header the supports I/O. The statement includes the
<iostream>, <stdio> header in a program. C++ & C
A variable is a named memory location. The contents of a variable can be
changed during the execution of a program.
A variable is a named memory location. The contents of a variable can be
changed during the execution of a program.
The keyword is for. In C++, all keywords are in lowercase.
A C++ identifier can contain letters, digits, and the underscore.
C++ is case sensitive.
Type parentheses ’( )’ and braces ‘{ }’ in pairs
Use parentheses for clarification in arithmetic expressions
Don’t forget semicolon at the end of each statement.
Analyze the problem properly, and then start coding (first think and then write).
-----------------------------------------------------------------------------------------------------------
S una w a r K ha n Ahs a n
For solution contact me at 03334892200
Mail: sk_ahsan38@yahoo.com
-----------------------------------------------------------------------------------------------------------