C++ Answers

Questions answered by Experts: 9 913

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Implement a class called Fractions having two private integer data members used for a


fraction’s numerator and denominator.


The Fraction Class’s default constructor should provide both data members with default values


of 1 if no explicit user initialization is provided. It must also prohibit 0 as the denominator


value.


Further, provide member functions for displaying an object’s data values i.e given an object,


its numerator and denominator. Also provide the class with member functions that are capable of


adding, subtracting, multiplying and dividing two Fraction objects according to the following


formulas:


Sum of two fractions: a/b + c/d = (ad + cb) / bd


Difference of two fractions: a/b – c/d = (ad – cb) / bd


Product of two fractions a/b * c/d = ac/ bd


Division of two fractions: a/b / c/d = ad /bc

Implement a class named Rectangle that contains following private members:



 Two double data fields that specify the width and height of the rectangle. A string data field, named color, that specifies the color of a rectangle.



You should provide a no-argument constructor that creates a default rectangle having width and



height of 2 units and color set to black. You should also provide an overloaded constructor that



creates a rectangle with the specified width and height. In addition you should provide methods



to only set the color of the rectangle. Further, you should provide a member function named



getArea() that returns the area of this rectangle and a function named getPerimeter() that returns



the perimeter.



Write a test program that creates two Rectangle objects. Assign width 10 and height 20 to the



first object and width 34.5 and height 15.9 to the second object. Assign color red to all



Rectangle objects and find their areas and perimeters.

Implement a class Address. An address has



 a house number,



 a street,



 a city,



 a state and



 a postal code.



Supply two constructors:



 the default no-argument constructor that initializes different members



 one with complete address.



 Supply a print function that prints the address with the street on one line and the city,



state, and postal code on the next line.



 Supply a method verifyAddress that tests whether an address is valid (and does not



contain default values)



 Supply a method compareTo that tests whether one address comes before another when



the addresses are compared by postal code



Write a small program to test your class.

Implement a class Student. A Student has a first name (string), last name (string) and CGPA (float).



Write a default constructor, an overloaded constructor with three parameters (first name, last



name and CGPA). In addition provide methods (functions) to return the full name and CGPA.



Write a small program to test your class by creating an object and invoking different functions



to get and set different class members.

WAP in C to calculate area and perimeter of rectangle, area and




circumference of circle using switch case statement.

Design an algorithm which gets a natural value, n, as its input and calculates odd numbers 

equal or less than n. Then write them in the standard output.


Write the definition of the function, nodeCount, that returns the number of nodes in a binary tree. Add this function to the class binaryTreeType and create a program to test this function


Question: Implement this program by using User-defined functions.



Write a function magicCheck that takes a one-dimensional array of size 16, a two-dimensional array of four rows and four columns, and the sizes of the arrays as parameters. By adding all the elements of the one-dimensional array and dividing by 4, this function determines the magicNumber. The function then adds each row, each column, and each diagonal of the two-dimensional array and compares each sum with the magic number. If the sum of each row, each column, and each diagonal is equal to the magicNumber, the function outputs ‘‘It is a magic square’’. Otherwise, it outputs ‘‘It is not a magic number’’. Do not print the sum of each row, each column, and the diagonals.


QUESTION: Implement this program by using User-defined functions


Write a program that prints the day number of the year, given the date in the form month-day-year. For example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. The program should check for a leap year. A year is a leap year if it is divisible by 4 but not divisible by 100. For example, 1992 and 2008 are divisible by 4, but not by 100. A year that is divisible by 100 is a leap year if it is also divisible by 400. For example, 1600 and 2000 are divisible by 400. However, 1800 is not a leap year because 1800 is not divisible by 400.


derive a class hierarchy for the item set given below.Item sets 



Engine , InternalCombustineEngine , ExternalCombustineEngine , PetrolEngine, DieselEngine, SteamEngine | Virtual Function GetEfficiency()


Please Note that Petrol Engine and Diesel Engines are Internal Combustion Engines and Steam Engine is External Combustion Engine. So arrange the Class hierarchy accordingly.. 


LATEST TUTORIALS
APPROVED BY CLIENTS