• No results found

C++ Programs

N/A
N/A
Protected

Academic year: 2021

Share "C++ Programs"

Copied!
7
0
0

Loading.... (view fulltext now)

Full text

(1)

Mr. Dinesh Kumar Bhawnani, BITD, 9827475115 Page 1 1. Write a C++ program, which reads a five-digit number, and find the sum of its digits.

2. Write a C++ program, which reads a five-digit number, and reverse that number. 3. Write a C++ program, which reads a number, and find whether it is even or odd. 4. Write a C++ program, which reads a number, and find whether it is prime or not. 5. Write a C++ program, which reads a year and find whether the entered year is leap or not.

6. Write a C++ program, which reads a number, and find the prime numbers from 1 to that number. 7. Write a C++ program to read the numbers and find the largest between

• Two numbers • Three numbers

• Four numbers by using switch case statements.

8. Write a C++ program to print the following patterns using loops. 1) 1 1 2 1 2 3 1 2 3 4 2) 1 2 3 4 5 6 7 8 9 10 3) 1 2 1 2 3 2 1 2 3 4 3 2 1 2 3 4

9. Write a C++ program to find sum of the first natural numbers: Sum = 1+2+3+…+100 by using

• For loop • While loop • Do while loop

10. Write a C++ program to find sum of the following series using function declaration. Sum = x – (x)3/3! + (x)5/5! -.. (x)n/n!

11. Write a C++ program to read two matrixes and to perform the matrix multiplication. 12. Write a C++ program to exchange the contents of two variables using

• Call by value • Call by address • Call by reference

13. Write a C++ program to find the factorial of a given number using recursive function. 14. Write a C++ program to generate a fibonacci series up to 10 terms using recursive function. 15. Write a C++ program to add two integers, two floats and two doubles using function overloading. 16. Write a C++ program to perform swapping of two data items of integer, floating point number

and character type with the help of function overloading. 17. Write a C++ program to find the length of a string using pointers. 18. Write a C++ program to compare two strings using pointers. 19. Write a C++ program to concatenate two strings using pointers.

(2)

Mr. Dinesh Kumar Bhawnani, BITD, 9827475115 Page 2 21. Write a C++ program to input the name of an employee along with their basic salary and find his gross

salary using structure. (DA = 70% of basic salary & HRA = 10% of basic salary).

22. Write a C++ program to perform the following arithmetic operations of a complex number using a structure.

• Addition of two complex numbers. • Subtraction of two complex numbers. • Multiplication of two complex numbers. • Division of two complex numbers.

23. Write a C++ program to find the sum of two numbers using command line arguments.

24. Write a C++ program that accept a number and find the factorial of that number using command line arguments.

25. Write a C++ program that accept the name and basic salary of an employee and find their gross salary using command line arguments. (For calculating the gross salary the DA is 70% of basic salary and HRA is 10% of basic salary).

Classes & Objects

1. Write an OOP program, which reads two numbers, calculate the smallest one and print the smallest one. 2. Write an OOP program which reads two numbers and prints sum of these two numbers.

3. Write an OOP program which performs the following operations • Addition of two matrixes.

• Subtraction of two matrixes. • Multiplication of two matrixes.

4. Write an OOP program which reads two complex numbers and perform the following operations • Addition

• Subtraction • Multiplication • Division

5. Write an OOP program to find the roots of a quadratic equation.

6. Write an OOP program to read the name of 10 employees along with their basic salary and find their gross salary. (DA = 70% of basic salary and HRA = 10 % of basic salary).

7. Write an OOP program to access the private data members of a class by non-member function where the function is declared:

• Is the location of public category • Is the location of private category

• Within the scope of class definition itself • Defined with inline code substitution.

8. Write an OOP program to find the maximum of data members of two different class using friend functions.

9. Write an OOP program to exchange the private data members of two different functions using friend functions.

10. Write an OOP program to define a class to represent a bank account. Including the following members. Data members

(3)

Mr. Dinesh Kumar Bhawnani, BITD, 9827475115 Page 3 • Account number

• Type of account

• Balance amount in the account Member Functions

• To assign initial values • To deposit an amount.

• To withdraw an amount after checking the balance • To display name and balance

11. Write an OOP program to define a class to represent a vector (a series of float values). Include member functions to perform the following tasks:

• To create the vector

• To modify the value of a given element • To multiply by a scalar value

• To display the vector in the form (10, 20, 30…)

12. Write an OOP program which reads the name of a person and five different account number of that and then find out account number 2323 is belong to that or not. Note that for storing account number use an array.

13. Write an OOP program which reads the bio-data of 10 employees of a factory and then print the bio-data of those employees whose salary is more than 15000. The employee bio-data consist of following field

• Name • Age • Gender • Designation • Salary • Experience

14. Write an OOP program which prints the object number whenever we create an object.

15. Write an OOP program to count how many times a particular member function of a class be called by • A particular object

• Any objects

16. Write an OOP program to define a constructor for a “Date” class that initializes the Date objects with initial values. In case initial values are not provided, it should initialize the objects with default values. 17. Write an OOP program to define a class whose constructor can be used to perform following functions:

• Create un-initialized strings

• Create objects initialized with a string Member Functions

• To concatenate two strings and display the concatenated string • To display the contents of the objects

18. Write an OOP program to define a class for a book shop which has following Data Members

• Book title

• Name of the publisher • Stock position of the books • Book price in Rupees • Total sales in Rupees

(4)

Mr. Dinesh Kumar Bhawnani, BITD, 9827475115 Page 4 • To search for the book (using book title)

• To sell the book and update the stock • To show the stock position

• To show the total sales

19. Write an OOP program, which reads a complex number, and copy that into another using copy constructor.

20. Write an OOP program to generate a series of fibonacci numbers using the constructor where the constructor member function had been defines

• Is the scope of class definition itself.

• Out of the class definitions using the scope resolution operator. Also make this program with the help of the copy constructor.

Operator Overloading

21. Write an OOP program to overload unary – operator to change the sign of private data member of a class.

22. Write an OOP program to concatenate two strings by overloading + operator using • Member function

• Friend Function

23. Write an OOP program to overload < (less than) operator to find which of the two string object is greater and show the greater string object.

24. Write an OOP program to overload = = operator to compare two strings.

25. Write an OOP program to perform simple arithmetic operations of two complex numbers using operator overloading.

26. Write an OOP program to overload = operator to copy the contents of one string object to another string object.

27. Write an OOP program to generate fibonacci series by overloading • Prefix operator

• Postfix operator

Inheritance

28. Write an OOP program to create a class “Stdnt_base” which has the following members: - • Student name

• Department • Roll number • Semester

Member Functions

• To fill up the necessary data for every student • To search for the student using name as the key • To show all the information

Create another class “Stdnt_Info” which should be derived from “Stdnt_base” and has the following members:-

(5)

Mr. Dinesh Kumar Bhawnani, BITD, 9827475115 Page 5 • Total marks

• Total percentage Member Functions

• To fill up the necessary data • To calculate marks and percentage

• To show the final report containing all the data (from name to total percentage) related to all the

students.

29. Write an OOP program to create a class “Emp_data” which has the following members:- • Employee name

• Employee grade Member Functions • To input data • To display the data

Create another class “Emp_personal” which has the following members:- • Permanent address of the employee

• Educational qualifications of the employee Member Functions

• To fill up the data • To show the data

Create another class “Emp_info” derived from “Emp_data” and “Emp_personal” whih has the following members:-

• Employee salary Member Functions

• To fill up all the data (from name to salary) • To search for a particular employee (by name)

• To display all the information about all the employees 30. Create a class “Accnt_amt” which has the following members:-

• Account number

• Total balance amount in the account Member Functions

• To fill data • To show data

Create a class “Accnt_deposit” which has the following members:- • Latest amount deposited

Member Functions • To fill data

• To show data

Create a class “Accnt_withdraw” which has the following members:- • Latest amount withdrawn

Member Function • To fill only valid data • To show data

Create a program which can be used o fill and withdraw any amount & search any account.

31. Write an OOP program to demonstrate how ambiguity can be avoided using scope resolution operator in the following inheritance

(6)

Mr. Dinesh Kumar Bhawnani, BITD, 9827475115 Page 6 • Single Inheritance

• Multiple Inheritance

32. Write a Program to demonstrate how a pure virtual function defined declared and invoked from the object of derived class through the pointed of the base class.

33. Design a base class which has following data:- • Name

• Rollno • Phno • Address

Then design a derived class from above base class in derived class the data are:- • Marks in first session

• Marks in second session • Total marks

The program which consist above base and derived class perform following operation • Create a database

• Insert a new entry • Delete an entry • Modify entry

• Print all the entry in database

File Handling

34. Write a program to count the number of words in a given text file.

35. Write a program to store every character typed on the keyboard in to a file. When the user presses the ESC key then the program should stop.

36. Write a program to Encrypt and Decrypt a text file. Using a text Menu.

37. Write a program to copy the contents of one text file to another and display both the files. Using a text Menu.

38. Write a program to concatenate one file at the end of another and print both the files. Using text menu. 39. Create a database of 10 students. The database should contain the Name, Marks of 5 subjects, Aggregate

Marks, Aggregate percentage and Division according to the following conditions: - • Percentage above or equal to 60 – First division.

• Percentage between 50 and 59 – Second division. • Percentage between 40 and 49 – Third division. • Percentage below 40 - Fail

Display the above database of every student in a tabulated form.

Implement the above program using Structures, Text-Menu and File I/O operations.

40. Create a database for a Shop containing 10 items. The First part of the database should contain the Name of item, serial number of item, Unit price of item and Sale of the day. The Second part of the database should contain the Customer name, Items purchased and total purchase.

Create a Menu that should have the options of following types: -

• Filling up the first part of the database related to the items of the shop.

• Filling up the second part of the database related to the customer information. • List of Item names with item serial number and corresponding unit costs.

(7)

Mr. Dinesh Kumar Bhawnani, BITD, 9827475115 Page 7 • Purchase option for purchasing any item depending upon the selected item serial number.

• Sale of the day.

• Total Purchase done, containing Item units, corresponding prices and Grand total. • Exit for closing the program.

Implement the above program using Structures, Text-Menu and File I/O operations.

41. Create a database of 10 employees in a firm containing three departments – EDP, HR and Finance. The database should contain Employee name, Employee ID number, Department, Post held, Basic salary, DA, HRA, Gross salary according to the following conditions: -

• If Basic less than Rs5000.00 then HRA=10% and DA=90% of the basic salary.

• If Basic salary greater than Rs5000.00 and less than or equal to Rs15000 then HRA=20% and DA=61% of the basic salary.

• If Basic salary greater than Rs15000 then HRA=30% and DA=72% of the basic salary. Using a Menu do the following activities: -

• Filling up the database.

• Displaying all information related to any selected employee (Name, ID number, Department, Post held, Basic salary, HRA, DA, Gross Salary)

• Displaying all information about all the employees. • Searching for any employee.

• Exit the program.

Implement the above program using Structures, Text-Menu and File I/O operations. Exception handling & Templates

42. Write a C++ program to find the maximum between two integers, two floats and two doubles using templates.

43. Write a C++ program to define a swap function template for swapping two objects of the same type. 44. Write a C++ program to read two numbers and find the division of these two numbers using exception

handling.

45. Write a C++ program to create a function which take an integer as a argument and raise an exception integer found if the value of argument is > 0, raise an exception character found if value of argument is = 0,raise an exception float if the value of argument is < 0.

46. Write a C++ to create a function which take a parameter is the value of parameter is > 0 then throw integer type, is parameter is = 0, then throw character type, if parameter is < 0 then throws float type exception but for all design use only one catch block.

47. Write a Program to Bubble Sort using template function.

48. Write a Program for invoking for that Generate & Handle exception.

49. Write a OOP program to define and declare a class template for reading two data items from keyboard and to find the sum of the given two data items.

50. Write an OOP program using a class template to read any five parameterized data type such as float and integer, and print the average.

References

Related documents

i) Maximum Rs. iii) Maximum Rs. iv) The acquisition or construction should be completed within 3 years from the end of the financial year in which the HBL taken. In case of

Adjusted gross salary for any year is a participant’s gross University salary (including any shift differential, summer or equivalent term salary, health science faculty income

adjusted gross salary for any year is a participant’s gross university salary (including any shift differential, summer or equivalent term salary, health science faculty income

The EDHEC-Risk Institute Executive MSc in Risk and Investment Management programme faculty is an exceptional team of international experts who blend academic excellence and

Limonium oligotrichum Limonium tubiflorum Limonium bocconei Limonium aucheri Limonium cephalonicum Limonium gymnesicum Limonium saracinatum Limonium multiflorum Limonium

The fact that 51 percent of the Open Source market investigates 2.24 proprietary PBXs demonstrates that businesses choosing Open Source address the process with an

• By making voluntary contributions to an individual account of a severance pay fund established by an employer under Labour Code regulations, individuals are entitled to

Effective management must take into account not only the financial data, as they are presented in business annual financial statements, but the way culture affects quantitative