Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

3rd Assignment, COL100

Semester II, 2015-2016

Sample Program
The following program sample.cpp takes an integer as input and returns its squared value. Notice that cin
is used to read input values and cout is used to print values to the screen.
Dont worry if you dont understand everything in the code below (later on, you will). For now, you may
want to add the content of lines numbered between 1 to 5 and 12 and 13 to your code. Use logic to develop
the rest of the code to meet the requirements of the problem.

1
2
3
4
5
6
7
8
9
10
11
12
13

#include<iostream>
using namespace std;
int main()
{
int num;
cout << "This program will print the square of an input integer" << endl << endl;
cout << "Enter input number: ";
cin >> num;
cout << "You entered " << num << endl;
cout << "Squared number is " << num * num << endl;
return 0;
}

When you run this code on a terminal/Eclipse, you will see something like:
anup@anup-laptop:~$ g++ sample.cpp
anup@anup-laptop:~$ ./a.out
This program will print the square of an input integer
Enter input number: 4
You entered 4
Squared number is 16

Point in a Rectangle
In this assignment, you will help us decide the following: given an axis-parallel rectangle in the Euclidean
plane whether a test point lies strictly inside the rectangle, outside the rectangle, or on the rectangle. You
will be given coordinates for the top-left and bottom-right points of the rectangle, and a test point. Design
your program to meet the following requirements.
Read the top-left point.
Read the right-bottom point.
Read the test point.
If input is erroneous, output -1 and exit.
Output 1 if the test point lies strictly inside the rectangle; 2 if it lies outside the rectangle; 3 if it lies
on the rectangle.
General Points: Your submission will be evaluated based on a number of test cases. Make your submission
as general as possible. In the final submission do not include anything except what is asked for in the
question. For example, do not print any message saying give the coordinates for the points. Assume those
values are given and print answers in the expected format.

You might also like