C Assignments2
C Assignments2
Class
Q1. Class Employee contain the following members:
Class name Employee
Data members/ instance variables
Empname To store the name of employee
Empcode To store the employee code
Basicpay To store the basic pay of the employee
Member functions/methods
Employee() constructor to initialize all data members/ instance
variables to null.
Employee(………) Constructor to assign name, employee code and
basic salary to data members / instance variables
Double salarycall () To compute and return the total salary of the
employee.
The salary is calculated according to the following rules:
Salary=Basic salary+HRA+DA
HRA=30%of basic salary
DA=40%of basic salary
Q2. Define a class BOOK with following Specifications:
Private members of the class BOOK are
BOOK_No integer type
BOOK_Title 20 characters
Price float (Price per copy)
Total_cost () A function to calculate the total cost for N number of
copies, where N is passed to the function as argument.
Public members of the class Book are
Input () Function to read BOOK_NO, BOOK_Title, Price
Purchase () Function to ask the user to input the number of
copies to be purchased. It invokes Total Cost () and prints the total cost to be
paid by the user.
Q3. Declare a class to represent bank account of 10 customers with the
following data members.
Name of depositor, Account number, Type of account (S for saving and C for
Current),
Balance amount. the class also contains member functions to do the
following:
i. To initialize data members
ii. To deposit Money
iii. To withdraw money after checking the balance (minimum balance in Rs.
1000)
iv. To display the data members.
Q4. Design a program in c++ to calculate the tax:
Specify a class taxpayer whose class description is given below:
Class name taxpayer
Data member int pan - to store the personal account number.
Char name [20]-to store the name of a person.
Float taxableinc- to store the total annual taxable income
Float tax- to store the tax that is calculated
Member Function inputdata () – to input data for a taxpayer
Displaydata () – to display data for taxpayer
Computetax () – to compute tax for a taxpayer.
The tax is calculated according to the following rules:
Total Annual taxable Income Rate of Taxation
Upto 500000 0%
Any amount above 500000 but up to 1000000 20%
Any amount above 1000000 but up to 2000000 30%
Any amount above 2000000 35%
Q5. Create a class called 'Matrix' containing constructor that initializes the
number of rows and the number of columns of a new Matrix object. The
Matrix class has the following information:
1 - number of rows of matrix
2 - number of columns of matrix
3 - elements of matrix (You can use 2D vector)
The Matrix class has functions for each of the following:
1 - get the number of rows
2 - get the number of columns
3 - set the elements of the matrix at a given position (i,j)
4 - adding two matrices.
5 - multiplying the two matrices You can assume that the dimensions are
correct for the multiplication and addition.
Q6. Write a program to print the area and perimeter of a triangle having sides
of 3, 4 and 5 units by creating a class named 'Triangle' with a function to print
the area and perimeter.
Q7. Write a program to print the area of a rectangle by creating a class named
'Area' having two functions. First function named as 'setDim' takes the length
and breadth of the rectangle as parameters and the second function named as
'getArea' returns the area of the rectangle. Length and breadth of the
rectangle are entered through keyboard.
Q8. Print the sum, difference and product of two complex numbers by creating
a class named 'Complex' with separate functions for each operation whose real
and imaginary parts are entered by the user.
Q9.Create a class FLOAT that contains one float data member .overload all the
four arithmetic operators so that they operate on the objects of FLOAT.
Q10.Define a class String . Use overloaded == operator to compare two
strings.
Q11.Create a base class called shape. Use this class to store two double type
values that could be used to compute the area of figures. Derive two specific
classes called triangle and rectangle from the base shape.Add to the base class,
a member function get_data() to initialize base class data members and
another member function display_area() to compute and display the area of
figures.Make display_area() as a virtual function and redefine this function in
the derived classes to suit their requirements.
Using these three classes ,design a program that will accept dimensions of a
triangle or a rectangle interactively and display the area.
Area of rectangle=x*y;
Area of tringle =1/2*x*y
Q12 Program in C++ Using file handling to perform following operations:
1.Add new record
2.View all records
3.Delete particular record
4.Search record
Q13. Write a program to display content of file on screen. File name given by
user
Q13. Write a program to display content of Specified file on screen in the
following way.
[A] Upper Case
[B] Lower Case
[C] Title or Proper Case
Q14. Write a program to Create and display content of file on screen. File
name given by user
Q15. Write a program to display No. of Line, Space, Non- Alphabet, Alphabet of
file on screen. File name given by user.
Q16. Write a program that accept two file names first as a Source and second
as destination then copy first file content in second file.
Q17. Write a program to Combine two file content into Third file.
Q18. Write a program to Combine two file content into third file. And also add
Line Number at beginning of each line.
Q19. Write a program to print 1 to 100 and redirect output in a file.
Q20. Write a program that accept two file names first as a Source and second
as destination then copy first file content in second file in reverse Order.
Q21.. Write a program to find out the size of given file.
Q22. Write a program to print Nth character of a file. Value of N is given by
user.
Q23. Write a program, to compute the wage of labor (working on the daily
basis) as per the Following wage structure.
Hours Worked Rate Applicable Up to first 8 Hours Rs. 50.00
For next 4 Hours Rs. 10.00 per hour extra
For next 4 Hours Rs. 20.00 per hour extra
For next 4 Hours Rs. 25.00 per hour extra
For next 4 Hours Rs. 40.00 per hour extra
The output of the program should be like this:
Enter the Name of Employee: XXXXXXXX
Enter the total hours worked: 99 Total Wage: 9999.99
Q24. Write a program to read 10 Element in an array and print them. Q25.
Write a program to read N Element in an array and print them. Q26. Write a
program to read 10 Element in an array and print greatest and smallest among
them.
Q27. Write a program to read 10 Element in an array and count all even and
odd.
Q28. Write a program to read 10 Element in an array and print in reverse
order.
Q29. Write a program to reverse an array and after print it.
Q30. Write a program to read 10 Element in an array and sort it in ascending
order using Bubble sort.
Q31. Write a program to read 10 Element in an array and sort it in ascending
order using Selection sort.
Q32. Write a program to read 10 Element in an array and sort it in Descending
order using Bubble sort.
Q33.Write a program to read 10 Element in an array and sort it in Descending
order using Selection sort.
Q34. Write a program to read 10 Element in an array and print 2nd greatest
and 2nd smallest among them.
Q35.Write a program to read value in 2 matrix and print their Sum and Minus.
Q36.Write a program to read value in a matrix and print its value along with its
Row Total , Column Total and whole Total.
Q37.Write a program to read value in two Array A and B and put common
elements in to third Array C. and also print all array.
Q38.Write a program to read value in two Array A and B and merge elements
into third Array C in ascending order. and also print all array.
Q39.Write a program to read value in two Array A and B and merge elements
into third Array C in Descending order. and also print all array.
Q40.Write a program to read 10 values in integer array and print all value
stored at even position.
Q41. Write a program to input String using following functions and print it.
Using cin() b) gets() c) at declaration time
Q42. Write a program to read a String and print its length (without using library
function)
Q43. Write a program to read a string and copy it into another string.(Do not
use Library Function)
Q44. Write a program to read two String and concatenate it.(without using
library function)
Q45. Write a program to print given string in reverse order.
Q46. Write a program to read a string and a character. After that print the final
string by replacing all vowel characters of the string with given character.
Q47. Write a program to count the following in a given sentence. [A] Upper
case character [B] Lower case character [C] Digits [D] Vowels [E] Space
character [E] Words [F] Lines [G] Consonant
Q48. Write a program to count number of occurrences of each character in the
given string. if input is : “BANANA” then output will be following. B 1 A 3 N
2
Q49. Write a program to remove all extra spaces in a given String.
Q50. Write a program to sort given string in ascending order.
Q51. Write a program to sort given string in descending order.
Q52. Write a program to find the No. of Characters with space and without
space in a given String.
Q53. Write a Program that read Name of Person and print it in following
Format. If User Input “Shalini Singh Srinet” then it Print : [A] S.S.S. [B] S.S.Srinet
[C] Srinet S.S.
Q54. Write a Function that take 2 numbers and return smaller Value. Q55.
W.A.F. that take 2 numbers and return larger Value.
Q56. Write a recursive Function for calculate Factorial of a received Number.
And return to the calling function.
Q57. Write a recursive Function for Binary search.
Q58. W.A.F. that takes an integer type array of size 10 and return the greatest
number.
Q59. W.A.F. that takes an integer type array of size 10 and return the smallest
number.
Q60. W.A.F. that takes an integer type array of size 10 and return Sum of All
numbers.
Q61. W.A.F. that takes an integer type array of size 10 and return Sum of All
Even numbers.
Q62. W.A.F. that takes an integer type array of size 10 and return Sum of All
ODD numbers.
Q63. W.A.F. that takes an integer type array of size 10 and return Sum of All
Even position’s numbers.
Q64. W.A.F. that takes an integer type array of size 10 and return Sum of All
ODD position’s numbers