Professional Documents
Culture Documents
1.)
Create a calculator that takes a number, a basic math operator (+,-,*,/,^), and
a second number all from user input, and have it print the result of the mathema
tical operation. The mathematical operations should be wrapped inside of functio
ns.
2) Write a program that asks the user for an integer number and find the sum of
all natural numbers up to that number.
3) Write a program that checks if the angles given can make a triangle or not (t
heir sum must be 180 degrees).
4) Write a program that prints on the screen all the even numbers up to 10.
5) Write a program that tells you if a number is even or odd.
6) Write a class called rectangle with two private variables: double width, doub
le height. Write member functions for computing the area and the perimeter.
Write a default constructor, a regular constructor and accessors for width and h
eight. Demonstrate the use of this class in a main routine.
7) Write a function that takes as an argument an integer n. The function should
output the pattern:
a)
*
**
***
****
Where the triangle has n rows.
Repeat this exercise for a different pattern:
*****
****
***
**
*
and for
*****
****
***
**
*
and for
*
***
*****
*******
Note that in the above you always need an odd number of stars each row. Figure
out a reasonable way to do this.
8)
Passing by value vs. passing by reference
Write the output of the following program:
int fun (int a, int &b)
{
int c=3;
cout << a << " " << b << " " << c << "\n";
a+=b;
b++;
cout << a << " " << b << " " << c << "\n";
return b;
}
int main()
{
int a=10, b=20, c=30;
cout << a << " " << b << " " << c << "\n";
c = fun(b,a);
cout << a << " " << b << " " << c << "\n";
}
9)
You may assume that the graphics project has been set up for you and you only ne
ed to write a snippet of code for the ccc_win_main routine. In this problem we
use the default coordinate system for our graphics window. That is, the top lef
t point is (-10,10) and the bottom right is (10,-10). (You may assume this is a
lready set up for you.)
Write code that creates a circle of radius 1 at all integer coordinate points.
That is, draw a circles centered at points (-10,10), (-9,10), ... ,(9,10),(10,10
), (-10,9),
(-9,9), ... ,(9,9),(10,9) ...
10)
A class called Fraction consists of private variables int numerator and int den
ominator. The Fraction class has a member function called get_value() that tak
es no arguments and returns a double. It has regular and default constructors.
It also has an operator member function + that takes as an argument another Frac
tion object and returns a Fraction object.
Here is an example of how the class might be used in a program:
Fraction A(5,3); // numerator set to 5 denominator set to 3
Fraction B(1,7); // numerator set to 1 denominator set to 7