Vous êtes sur la page 1sur 1

Lab06: C++ Programming OSL, Week of 11th Feb 2013 Objective: 1. Write C++ programs for given problems.

2. Respond to survey on course feedback till now. General instructions: 1. This lab is to be done individually. Lab instructions: Exercise 1: cs101 midterm survey and feedback We would like to know your opinion about the course so far. Please fill out the survey form at:
https://docs.google.com/forms/d/1UoYcby_idtua0pPJQppAH7mng8NnRT1BtMip23UPGzc/viewform

This is anonymous so that you can write what you truly think, without concern of being identified. Please do nor proxy for others or give random responses, as it will defeat the purpose of this survey. Exercise 2: C++ program for Pascal's Triangle 1. Recall the Pascal's triangle problem in the Midsem. 2. Complete the Extra Credit part of the problem, i.e., write a program to Output the triangle upto the given Row, with appropriate number of spaces to get a visual formatting as shown. 3. Check if your program works as expected for various test cases. 4. Save your file as lab06-pascal.cpp. Exercise 3: Needle in a haystack 1. Generate 2 arrays of integers, needle and haystack, where both can have repeated elements, and neither is sorted. 2. Write code to remove all occurrences of any element in needle from haystack. The surviving elements of haystack must be kept in their original order. You can change needle in any way convenient to you. For example, if haystack = (5, 2, 3, 1, 3, 4, 1) and needle = (2, 3, 2) then on termination haystack should be (5, 1, 4, 1). 3. Save your file as lab06-needle.cpp. Exercise 4: Area of a Polygon A polygon P is convex if, for any two points a, b inside or on the boundary of P, every point c on the straight line segment connecting a and b is also inside or on the boundary of P. P can be described by first specifying the number of sides n, and then enumerating the coordinates (x0, y0), ..., (xn-1, yn-1) starting at an arbitrary vertex and going around the polygon in anti-clockwise order. Assume these inputs are stored in int n; double x[n], y[n]. We access (xi, yi) as x[i] and y[i]. Also assume no edge is parallel to the x- or y-axis. 1. Write a program to determine if the origin (0,0) is inside P or outside P. Hint: Find a point that will be inside the polygon and check if the origin is on the same side or opposite side of each side of P. 2. Find the area of the polygon. Hint: Split P into small triangles and compute. 3. Save your file as lab06-polygon.cpp. Before you leave today: Create a directory <rollnumber>_lab06, copy your files lab06-*.cpp to the directory, compress the directory and upload the tgz file on Moodle. <The End>

Vous aimerez peut-être aussi