Medium Programming Challenges
1) This challenge requires you to display a rectangular box-like figure having a
specified size, in a specified location, and using a specified character for
the border.
The input will consist of four items:
- width of the box (an integer > 0)
- height of the box (an integer > 0)
- indent level (an integer >= 0)
- character to be used to draw the border of the box
Note that the box width, box height, and indent level are all measured in
"number of character positions", either horizontally (in the case of width and
indent level, or vertically (in the case of height). Note also that an "indent level" of 0 (zero) means the box will be drawn with
its left side adjacent to the left margin.
Your program must read these values and then draw the corresponding box. Your
program must also display, on the line immediately above the box, a "ruler" to
provide an easy visual location indicator for the box.
2) The point of this challenge is to write a program that will accept two integers and output both the Greatest Common Factor and Lowest Common Multiple.
The Gcf is the greatest number that will divide into both.
The Lcm is the lowest number that is a multiple of both.
Any method is acceptable but the more concise the better.
3) The following program should function as a basic calculator; it should ask the user to input what type of arithmetic operation he would like, and then ask for the numbers on which the operation should be performed. The calculator should then give the output of the operation.
Fill in the missing parts of the code._______ <iostream>
___ multiply(int x, int y) { ______ x_y; }
____ divide(int x, int y) {
_____ x_y;
}
_____ add(int x, int y) { ______x_y; }
______ subtract(int x, int y) {
_____x_y;
} using namespace std; ___ _____()
{
____ op='c';
____ x, y; while(op!='e')
{ cout__"What operation would you like to perform: add(+), subtract(-), divide(/), multiply(*), [e]xit?"; cin__op; switch(op) { ____ '+': cin__x; cin__y; cout__x__"+"__y__"="__add(x, y)__endl_ break; ____ '-'_ cin__x; cin__y; cout__x__"-"__y__"="__subtract(x, y)__endl_ break; ____ '/': cin__x; cin__y; cout__x__"/"__y__"="__divide(x, y)__endl_ break; ____ '*'_ cin__x; cin__y; cout__x__"*"__y__"="__multiply(x, y)__endl_ break; _____ 'e': ______; ______: cout__"Sorry, try again"__endl; }
} return _;
_
There are no threads for this page.
Be the first to start a new thread.