Login(Email) Password Forget Password? Account Settings
Home ASP.net System Info C# Books Java Script Visual C++(MFC) C/C++ Win API Java Contact Us
Structures
A C++ Program to illustrate an example of structures
A C++ Program to illustrate passing structures to function
A C++ Program to illustrate pointers, structure and passing structure pointers to function
A C++ Program to illustrate pointers and an array of structure.
A C++ Program to illustrate pointers and an array of structure
A C++ Program to illustrate the relationship b/w union and structure.
A C++ Program to illustrate an array of structure.
A C++ Program to illustrate the use of nested structures.
A C++ Program to illustrate self-referential structures i.e. Linked List.
Classes
A C++ Program to illustrate classes with inline functions.
A C++ Program to illustrate classes with functions which are not inline.
A C++ Program to illustrate the role of constructor in classes
A C++ Program to illustrate the passing of values to constructor in classes.
A C++ Program to illustrate the overloading of constructors in classes.
A C++ Program to illustrate the role of destructor in classes.
A C++ Program to illustrate static class data.
A C++ Program to illustrate static member functions
A C++ Program to illustrate constant objects and constant member functions
A C++ Program to illustrate strings as member of classes.
A C++ Program to illustrate use of arrays as data items in classes.
A C++ Program to illustrate array of objects in classes.
A C++ Program to illustrate object initialization and assignment by default member wise copy.

Create a class called Complex for performing arithmetic with complex numbers. Write a driver program to test your class. Complex numbers have the form

 realPart + imaginaryPart * i

where i (under root)

is Use double variables to represent the private data of the class. Provide a constructor function that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided. Provide public member functions for each of the following:

a) Addition of two Complex numbers: The real parts are added together and the imaginary parts are added together.
b) Subtraction of two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand and the imaginary part of the right operand is subtracted from the imaginary part of the left operand.
c) Printing Complex numbers in the form (a, b) where a is the real part and b is the imaginary part.

Create a class called Rational for performing arithmetic with fractions. Write a driver program to test your class. Use integer variables to represent the private data of the class—the numerator and the denominator. Provide a constructor function that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form (i.e., the fraction 2/4  would be stored in the object as 1 in the numerator and 2 in the denominator). Provide public member functions for each of the following:
a) Addition of two Rational numbers. The result should be stored in reduced form.
b) Subtraction of two Rational numbers. The result should be stored in reduced form.
c) Multiplication of two Rational numbers. The result should be stored in reduced form.
d) Division of two Rational numbers. The result should be stored in reduced form.
e) Printing Rational numbers in the form a/b where a is the numerator and b is the denominator.
f) Printing Rational numbers in double floating-point format.
Modify the Time class of Fig. 6.10( in the deitel book how to program in c++) to include a tick member function that increments the time stored in a Time object by one second. The Time object should always remain in a consistent state. Write a driver program that tests the tick member function in a loop that prints the time in standard format during each iteration of the loop to illustrate that the tick member function works correctly. Be sure to test the following cases: a) Incrementing into the next minute. b) Incrementing into the next hour. c) Incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM).
Modify the Date class of Fig. 6.12 to perform error checking on the initializer values for data members month, day and year. Also, provide a member function nextDay to increment the day by one. The Date object should always remain in a consistent state. Write a driver program that tests the nextDay function in a loop that prints the date during each iteration of the loop to illustrate that the nextDay function works correctly. Be sure to test the following cases:

a) Incrementing into the next month.
b) Incrementing into the next year.
Combine the modified Time class of and the modified Date class  into one class called Date- AndTime Modify the ticks function to call the nextDay function if the time is incremented into the next day. Modify function printStandard and printMilitary to output the date in addition to the time. Write a driver program to test the new class DateAndTime. Specifically, test incrementing the time into the next day.
Modify the set functions in the program of Fig. 6.10 to return appropriate error values if an attempt is made to set a data member of an object of class Time to an invalid value.
Create a class Rectangle. The class has attributes length and width, each of which defaults to 1. It has member functions that calculate the perimeter and the area of the rectangle. It has set and get functions for both length and width. The set functions should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0.
Create a more sophisticated Rectangle class than the one you created in Exercise above program. This class stores only the Cartesian coordinates of the four corners of the rectangle. The constructor calls a set function that accepts four sets of coordinates and verifies that each of these is in the first quadrant with no single x or y coordinate larger than 20.0. The set function also verifies that the supplied coordinates do, in fact, specify a rectangle. Member functions calculate the length, width, perimeter and area. The length is the larger of the two dimensions. Include a predicate function square that determines if the rectangle is a square
Modify the Rectangle class of program to include a draw function that displays the rectangle inside a 25-by-25 box enclosing the portion of the first quadrant in which the rectangle resides. Include a setFillCharacter function to specify the character out of which the body of the rectangle will be drawn. Include a setPerimeterCharacter function to specify the character that will be used to draw the border of the rectangle. If you feel ambitious, you might include functions to scale the size of the rectangle, rotate it, and move it around within the designated portion of the first quadrant.
Create a class TicTacToe that will enable you to write a complete program to play the game of tic-tac-toe. The class contains as private data a 3-by-3 double array of integers. The constructor should initialize the empty board to all zeros. Allow two human players. Wherever the first player moves, place a 1 in the specified square; place a 2 wherever the second player moves. Each move must be to an empty square. After each move, determine if the game has been won or if the game is a draw. If you feel ambitious, modify your program so that the computer makes the moves for one of the players automatically. Also, allow the player t o specify whether he or she wants to go first or second. If you feel exceptionally ambitious, develop a program that will play threedimensional tic-tac-toe on a 4-by-4-by-4 board (Caution: This is an extremely challenging project that could take many weeks of effort!).
Create a SavingsAccount class. Use a static data member to contain the annualInterestRate for each of the savers. Each member of the class contains a private data member savingsBalance indicating the amount the saver currently has on deposit. Provide a calculateMonthlyInterest member function that calculates the monthly interest by multiplying the balance by annualInterestRate divided by 12; this interest should be added to savingsBalance. Provide a static member function modifyInterestRate that sets the static annualInterestRate to a new value. Write a driver program to test class SavingsAccount. Instantiate two different savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 3%, then calculate the monthly interest and print the new balances for each of the savers. Then set the annualInterestRate to 4% and calculate the next month’s interest and print the new balances for each of the savers.

Create a class called IntegerSet. Each object of class IntegerSet can hold integers in the range 0 through 100. A set is represented internally as an array of ones and zeros. Array element a[ i ] is 1 if integer i is in the set. Array element a[ j ] is 0 if integer j is not in the set. The default constructor initializes a set to the so-called “empty set,” i.e., a set whose array representation contains all zeros.

Provide member functions for the common set operations. For example, provide a unionOfIntegerSets member function that creates a third set which is the set-theoretic union of two existing sets (i.e., an element of the third set’s array is set to 1 if that element is 1 in either or both of the existing sets, and an element of the third set’s array is set to 0 if that element is 0 in each of the existing sets).

Provide an intersectionOfIntegerSets member function that creates a third set which is the set-theoretic intersection of two existing sets (i.e., an element of the third set’s array is set to 0 if that element is 0 in either or both of the existing sets, and an element of the third set’s array is set to 1 if that element is 1 in each of the existing sets). Provide an insertElement member function that inserts a new integer k into a set (by setting a[k] to 1).

Provide a deleteElement member function that deletes integer m (by setting a[m] to 0).

Provide a setPrint member function that prints a set as a list of numbers separated by spaces. Print only those elements that are present in the set (i.e., their position in the array has a value of 1). Print --- for an empty set. Provide an isEqualTo member function that determines if two sets are equal.

Provide an additional constructor to take five integer arguments which can be used to initialize a set object. If you want to provide fewer than five elements in the set, use default arguments of -1 for the others.

Now write a driver program to test your IntegerSet class. Instantiate several IntegerSet objects. Test that all your member functions work properly.

Inheritance
A C++ Program to illustrate an example of Inheritance
A C++ Program to illustrate over-riding of base class member function in a derived class
A C++ Program to illustrate the difference among public, protected and private inheritance.
A C++ Program to illustrate the multi-level inheritance
A C++ Program to illustrate multiple inheritance
A C++ Program to illustrate an example of containership
Write an inheritance hierarchy for class Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the base class of the hierarchy. Make the hierarchy as deep (i.e., as many levels) as possible. The private data of Quadrilateral should be the (x, y) coordinate pairs for the four endpoints of the Quadrilateral. Write a driver program that instantiates and displays objects of each of these classes
Polymorphism
A C++ Program to illustrate an example of Polymorphism.
A C++ Program to illustrate an example of Polymorphism. [ Pure Virtual functions ]
Operator Overloading - Type Casting
A C++ Program to illustrate unary operator [ increment operator ++ ] overloading. [ without return type ]
A C++ Program to illustrate unary operator [ increment operator ++ ] overloading. [ with return type ]
A C++ Program to illustrate the binary operator [ + ] overloading. [ by creating a new object ]
A C++ Program to illustrate operator overloading in strings
A C++ Program to illusrate comparision operator [ < ] overloading
A C++ Program to illustrate unary operator [ decrement operator -- ] overloading. [ without return type ]
A C++ Program to illustrate unary operator [decrement operator --] overloading. [ with return type ]
A C++ Program to illustrate the binary operator [ - ] overloading. [ by creating an object of that class ]
A C++ Program to illustrate the binary operator [ + ] overloading. [ without creating a new object ]
A C++ Program to illustrate the binary operator [ - ] overloading. [ without creating an object of that class ]
A C++ Program to illustrate the binary operator [ * ] overloading. [ without creating a new object ]
A C++ Program to illusrate the use of stream insertion [ >> ] and extraction [ << ] operators.
A C++ Program to illusrate data conversion between built-in data types.
A C++ Program to illusrate data conversion between built-in data types and user defined data types [ int & float ].
A C++ Program to illusrate data conversion between built-in data types and user defined data types [char].
A C++ Program to illusrate data conversion user defined data types using functions
A C++ Program to illusrate data conversion user defined data types using constructor
A C/C++ program (source code) (deital how to program solution) Create a Date class with the following capabilities:
a) Output the date in multiple formats such as
DDD YYYY
MM/DD/YY
June 14, 1992
b) Use overloaded constructors to create Date objects initialized with dates of the formats in part (a).
c) Create a Date constructor that reads the system date using the standard library functions of the ctime header and sets the Date members.
Friend Functions and Friend Classes
A C++ Program to illusrate the use of friend functions.
A C++ Program to illustrate the use of friend classes
Template Function
A C++ Program to interchange the values of two int, float and char using function templates
A C++ Program to illustrate template classes
Misc. Programs
A C++ Program to find number of days b/w two given dates.
A C++ Program to capitilaize the first charcter of every word in a string.
A C++ Program to copy 'n' number of characters from one string to another at position 'p'.
A C++ Program to check whether a word is palindrome or not. [ using classes & pointers ]
A C++ Program to implement Add and Subtract functions on Big Number Class.