here - CENG241

Çankaya University
Computer Engineering Department
CENG 241 Advanced Programming
Lab Exercise
Prepared by:Pelin Güvenç
1.) Create a struct/class called Rational for performing arithmetic operations with
fractions. Notice that a fractional number is in the format; a/b. So your struct should have
two integers; the numerator and the denominator. Be careful about the “0” denominator.
Make sure that the user does not input a zero for the denominator.
Include the following functions/methods;
1. Adding two Rational numbers.
2. Subtracting two Rational numbers.
3. Multiplying two Rational numbers.
4. Dividing two Rational numbers. (All of the results should be stored in
reduced form.)
5. Printing Rational numbers in the form a/b, where “a” is the numerator and
“b” is the denominator.
6. Printing Rational numbers in floating-point format.
Write a main function to test your struct and the functions.
2.) Develop a struct/class called Polynomial. The internal representation of a
Polynomial is an array of terms. Each term contains a coefficient and an exponent.
The term
2x4
has the coefficient 2 and exponent 4. So basically it has two values in it’s array.
Include the following operations in your program;
a.) Addition; to add two Polynomials.
b.) Subtraction; to subtract two Polynomials.
c.) Multiplication; to multiply two Polynomials.
d.) Printing the Polynomials in the form; ax2+bx+c. Your solutions and
calculations should all be in that form.
Write a main function to test your struct and the functions.
3.) Create a struct/class called Complex for performing arithmetic operations with
complex numbers. Your struct should have two integer variables; the real part and the
imaginary part, considering that a complex number is in the format; a + bi.
Include the following functions;
1. Adding two Complex numbers.
2. Subtracting two Complex numbers.
3. Multiplying two Complex numbers.
4. Dividing two Complex numbers.
5. Printing Complex numbers in the form a + bi, where “a” is the real part
and “b” is the complex part.
The followings can be helpful when implementing your functions;
Addition:
Subtraction:
Multiplication:
Division:
4.) Create a struct/class called IntegerSet for which each object can hold integers in
the range from 0 to 100. A set is represented 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 j is not in the set. Don’t forget
to initialize your sets to “empty-set” (a set whose array representation contains all zeros).
Provide the following functions for your set operations;
- unionOfSets member function that creates a third set that is the union of the
other two sets.
- intersectionOfSets member function which creates a third set that is the
intersection of the two sets.
- insertElement member function that inserts a new integer k into a set by
setting a[ k ] to 1.
- deleteElement member function which does the exact opposite of
insertElement.
- printSet member function which prints out the existing elements of the set and
prints --- if the set is empty.
- isEqualTo member function which determines whether the sets are equal.