C++ worksheet

advertisement
1.0 find the area of a triangle, A, having base and height as b and h respectively as a floating data types of
inputs.
2.0 write a c++ program that converts a temperature value accepted from the user in degree celcious in to
faharanite scale.
Hint F=9/5xC+32
3.0 A C++ program that runs as an arithmetic operation on two inputs as x and y from the key board as
integers and performs to the followings.





Addition.
Subtraction.
Multiplication.
Division.
Modulus (Remainder) of the division.
4.0 A C++ program that manipulate on the logical operation of two inputs given from the key board as integer
data types and operate as:
 Bitwise Logical AND operation.
 Bitwise Logical OR operation.
 Bitwise Logical_ XOR operation
5.0 write a program to execute the following structure to you.
XXXXXX
X
XXXX
X
XXXXXX
6.0 Assuming there is 7.481 gallons in cubic foot write a program that asks the user to enter a number of
gallons and display the equivalent in cubic feet.
7.0 write a program that generates the following table.
1990
1991
1992
1993
135
7290
11300
16200
8 write a program that generates the following output using 10 as initial input and recommended operators.
10
20
19
Hint Use an integer constant for the 10, as arithmetic assignment operator to generate 20, and decrement operator to
generate 19.
9.0 On a certain day the British pound was equivalent to $1.487 us dollar, the French franc was $ 0.172, the
German Dutch was $ 0.584 and Japanese yen was $ 0.00955.Write a program that allows the user to enter
amount in dollar and display this value converted to these four monetary units.
10 Write a program that assigns value of 5 for both variable, a and b post and pre increment the variables and
assign them for variables d and e;
i.e. Initialize as
a=5;
b=5;
d=a++;
e=++b;
Display the result of a, b, d and e.
Repeat the above for decrement operator for post and pre cases:
11 Accept an alphabetical character from the key board and convert (cast) it to equivalent ASCII value.
12 Accept a number from the key board and find its square root as a double data type.
13 write a program that solves two simultaneous equations having inputs from the key board as the following type:
ax+by=e1;
cx+dy=e2;
Note: a, b, e1, c, d and e2 are the inputs and solve for x and y
14 A program that accepts the coefficients of quadratic equation as double data type and calculate roots as r1 and r2.
15 write a c++ code that accepts the mark of a student and points out his /her score of grade as the grading
system is shown below.
90≤mark≤100……….score =A;
80≤mark<90…………..score=B;
65≤mark<80…………..score=C;
40≤mark<65…………..score=D;
0≤mark<40……………..score=F;
Remember that your program has to identify weather valid data is given or not (consider for invalid inputs for mark<0 and
mark>100 and comment them as invalid inputs).
16 write c++ code to find the maximum of 3 inputs a, b, and c from the key board as integer data types.
17 write a c++ code to find Fibonacci series having the following structure and the maximum range is M.
Fibonacci series
1 1 2 3 5 8 13 21 ………………………M.
18 Write a program in c++ to accept a single character from the keyboard and using cout,display the character or key
stroke and its decimal, hexadecimal and octal values . Hint :use the set base manipulator for the conversion of the base
values and your display has to be in the following way.
Character
decimal
…………….
………..
hexadecimal
……………….
octal
………
19 accept two numbers from the keyboard and check whether one is a multiple of the other or not.
20 write a c++program that accepts a 4 digit number from the user and finds the reverse of the digits.
21 using simple if …else structure find the maximum of two numbers accepted from the keyboard.
22 write nested if..else program to find the maximum of three inputs from the user .
23 using switch statement find the month of the year depending on the number given from keyboard.
Note: use September as your initial month.
24 write a c++ program using for loop that displays your name three times.
25 Write a c++ program that finds the sum and average of any numbers you have from the key board using for loop.
26 Using the for loop structure generate the following shape of output
a)
b)
1
1 2
1 2 3
1 2 3 4
1
2 2
3 3 3
4 4 4 4
27 write a c++ program that finds the cube of natural numbers less than 11.
The output of your pattern should be in the following format.
1
2
3
.
.
.
10
1
8
27
.
.
.
1000
28 Using while loop write a c++ program that displays the first 20 odd numbers starting from 1.
1 3 5 7………………………....n
29 Using while loop find the sum and average of numbers accepted from the user.
30 Repeat the above using do….while loop.
31 Using the continue statement write a c++ program that finds the sum of only positive numbers from the keyboard just
leaving the negatives.
32 write a c++ program in a continue statement to add only odd numbers less than 100.
33 write a c++ program to have the following pattern as an output .
Hint: use the continue statement with for loop
1
1 2
1 2 3 4
1 2 3 4 5 6
34 using the break control statement write a c++ program that finds the sum of only 10 positive integers .if zero or
negative is encounter display error or negative value is encounter .
35 write a c++program using goto which checks the possible negative or zero value of input data ,whenever it
is non zero or positive , it continues the while loop otherwise it displays as input data error or negative value
or zero is given.
36 write a c++program that finds and prints the numbers, squares and cubes using for, while and do….while
loop statements.
Note: the output should like;
Number
Square
………..
Cube
………..
………..
………..
…………
………….
37 Write a program in c++ to find the sum of the following series using
i) for loop
ii) while loop
iii) do…while loop
iv) continue control statement
v) goto control statement
a) Sum=1+2+3+……………..+n;
b) Sum=1+3+5+………………+n;
c) Sum=1+2+3+………………+n;
38 write a c++ program to read positive number n and to generate the following series using.
i) for loop
ii) while loop
iii) do……..while loop
a) Number =1 2 3 4……………n;
b) Number = 0 2 4 6…………...n;
c) Number = 1 3 5 7………………..n;
d) Number = 1 22 32 42 ………………n2 ;
e) Number = 1 23 33 43 53 ……………...n3 ;
39 using a function call display the output ‘This is my first program ’.
40 write a c++ program that finds the sum of two real numbers using function call.
41 develop a c++code to work on the four arithmetic operations, Addition, Subtraction,Division and Multiplication over
two inputs from the keyboard using function call.
Hint: you can use function names as adder( ),subtracter( ),divi( ) and Mult( ) as identifiers respectively.
42 Using function call write a c++ program that finds the sum of the following series of numbers
a) Sum = 1+2+3+4+…………………..+100;
b) Sum = 1+3+5+7+……………………..+99;
c) Sum = 1+22
32
42 52 +……………+ 2;//decide n by yourself
43 Write a c++ program to find the factorial of a given number m using function call.
44 using function call develop a c++ program that can find the minimum of the three input numbers from the user (keyboard).
45 Develop a c++ code using function that finds the roots of a quadratic equation having the coefficients from you.
Note: consider all the conditions and it should support to find the complex roots too.
46 using function calling write a c++ program to find the square root of a number you have from the keyboard
47 Write a c++ program that finds the grade of the student using function call if the grading conditions are as follows;
90≤mark≤100…………..A;
85≤mark≤89…………….B;
70≤mark≤84…………….C;
50≤mark≤69…………….D;
0≤mark≤49………………F;
48 write a c++ code to display the following structures using for loop
a)
X
X X X
X X X
X X X
X X
X
XX X X
X
X X
X
b)
X
X
X
X
X
X
X
X
X
X
49 write a c++ code that accepts 3x4 matrices and find the transpose of it using any control loop.
The matrices may be as below
1 3 4
2 6 8
9 5 7
50 write c++ code to display the following structure using the for loop
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
51 using while and do while loop find the sum of the following series.
ABC-
D-
1+2+3+……+M-1
12+22+32+……+M-12
1+1/2+1/3+……+1/M
1/2+2/3+3/4+…….+M-1/M
52 Write c++ code to list out all the multiples of 5 less than 100.
53 write c++ program that finds all factors of given number N.
54 write c++ code that identifies whether the given natural number is prime or not.
55 Using any looping and control statements of a c++ program, implement the following outputs
56 Write a c++ program that is going to check whether a digit d would exist in any number N you have from the
key. If it exists how many times does it exist in the number? Your program has to identify both the maximum
and minimum digits and as well the reverse of the digits of the no you have taken.
57 Using a define directive implement the following problem to find the functional value of f(x,y,z) for any value of x,y and z.
f(x,y,z) = (xy2z+x2yz3 +6)/((xy+6x)(y2 -4)(zy-8y))
58 Use a function call to implement the following problem
(xy2z3w4)/10 + (x2y3z4w5)/14 + ………+ (xnyn+1zn+2wn+3)/ (4n+6)
59 write a c++ code using a function call to find the sum of the squares of integers you have in between two
boundaries a, b. where a is taken as lower boundary and b is found to b the maximum.
60 Use a function call to identify the type of triangle you may have being given its 3 sides as x,y and z. your program
should be full and work for any type of triangle.
61 Evaluate the
a)
4
b)
t ih
i4
i
i2
h i
, and evaluated at x=3 for f(x)=4i3
62 Find the reverse of the digits of any number X and also find
a) The maximum and minimum digit
5i2
ti
b) How many times would any digit exist in the considered number X
63 using a function call ( user built in) ,write a C++ program that implements the following problems.
a. 1+2++ 3+ + 4+ +…………………………+ +
b. x+
c. x-
i2
2+
i3
3+
+
+
i3
3+
i5
5+
i4
+ 4+ +………………………………
-
i
+
+………………………… ±(x2n-1)/(2n-1)!
64 Use goto control statement to implement the following problems
F/f…………………..list out all the factors of any +ve integer M.
+
!/C/c……………..nCr ( o +o+ h for any r≤n
O/o/e/E………..odd and even sum of positive integers up to N
65 Use goto control statement to implement
0≤X≤3 ………………………….. Displays chase board
3<X≤6………………………………………
X<0||X>6 …………………………………….No task just good bye
66 If a linear interpolation is used to approximate a certain data and all the given data are supposed to be approximated by
a linear regression curve of least error square estimation method defined as y=ax+b, then write a C++ code for any
number of data that best fits a linear equation defined above. If for m number of sampled data is fed in paired xi and yi ,
(xi , yi). Where a and b are evaluated as shown below.
a=
i
i
__________________________
i2
i
2
i2
i
i
b= ____________________________________
i2
i
2
67 Use function call that accepts any time in seconds and convert it to standard time format HH:MM:SS (hour: minutes: Seconds)
68 Use function call to execute the binomial coefficients of the binomial expansion given below.
69
Download