This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS51 Assignment 5: Postincrement Due: Friday, 21 March 2008 at 5:00 PM. Total Points: 50 (including 10 style points) In this assignment, you will begin thinking about objects, and get used to reading and writing in C++. The goals of this assignment are: 1. Refresh your memory about C 2. Remember how pointers work 3. Begin to familiarize yourself with C++ 4. Practice writing C++ Before you begin, you may find it helpful to review the CS 51 style guide; it is much easier to write extremely poorly written C++ than it is to write extremely poorly written Scheme code. You will likely find it useful to having your text editor help you with indentation. Place your answers to written questions in answers.txt . You can copy over a template of answers.txt (and other important files) from the normal place. Youll want to run: cp r ~lib51/pub/assigns/asst5 ~/cs51/asst5 Notice ther , which is necessary because asst5 has a folder inside of it. 1 Warmup: C++ (9 points total) Exercise 1. 9 points (a) [2 points] Suppose we declare the following struct: { x, y; } point_t; 1 1 WARMUP: C++ CS51 Assignment 5: Postincrement Below, on the left find C functions and on the right find corresponding C++ functions. For each C/C++ pair, tell whether the functions are the same or different. For any that are different, write a C function equivalent to its C++ counterpart. dot(point_t a, point_t b) { ((a.x * b.x) + (a.y * b.y)); } quad(point_t a, point_t b) { a.x = b.x; a.y = b.y; ((a.x * a.x) + (a.y * a.y)); } dot(point_t &a, point_t &b) { ((a.x * b.x) + (a.y * b.y)); } quad(point_t &a, point_t b) { a.x = b.x; a.y = b.y; ((a.x * a.x) + (a.y * a.y)); } (b) [1 point] Convert the following C printing code to C++ using cout : printf("Grades for student %s: ", name); (i = 0; i < n; i++) { printf("%d>%f", i, grades[i]); (i < n1) printf(", "); printf("\n"); } (c) [2 points] Declare and implement a constructor for the Triangle class: Triangle { : Point a, b, c; : // Missing constructor! area (); perimeter (); translate( dx , dy); rotate( ang); isIsosceles (); }; (d) [2 points] Use your constructor to initialize a pointer to a Triangle and an instance of a Triangle. Assume you already have variables of type Point available, with any names you like. (e) [2 points] Imagine I also have classes Circle and Square . List as many features (methods and data) as you can that these three classes might have in common. You may 2 of 7 2 REVIEW: C AND POINTERS CS51 Assignment 5: Postincrement start by considering the members listed in the definition of...
View Full
Document
 Spring '08
 NAGPAL

Click to edit the document details