asst5 - CS51 Assignment 5: Post-increment Due: Friday, 21...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS51 Assignment 5: Post-increment 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 the-r , which is necessary because asst5 has a folder inside of it. 1 Warm-up: C++ (9 points total) Exercise 1. 9 points (a) [2 points] Suppose we declare the following struct: { x, y; } point_t; 1 1 WARM-UP: C++ CS51 Assignment 5: Post-increment 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 < n-1) 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: Post-increment start by considering the members listed in the definition of...
View Full Document

Page1 / 7

asst5 - CS51 Assignment 5: Post-increment Due: Friday, 21...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online