Laboratory 7. Programming Workshop 2 (CSCI 1061U) Faisal Qureshi.

Similar documents
C++ Structures Programming Workshop 2 (CSCI 1061U)

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

struct Buffer { Buffer(int s) { buf = new char[s]; } ~Buffer() { delete [] buf; } char *buf; };

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

CSCI 102 Fall 2010 Exam #1

a. a * c - 10 = b. a % b + (a * d) + 7 =

CSS 343 Data Structures, Algorithms, and Discrete Math II. Polymorphism. Yusuf Pisan

Introduction to C++ (Extensions to C)

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

Inheritance, and Polymorphism.

Object oriented programming

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

Use the template below and fill in the areas in Red to complete it.

Sample Code: OUTPUT Daily Highs & Lows

WARM UP LESSONS BARE BASICS

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015

CSCE Practice Midterm. Data Types

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

Due Date: See Blackboard

Use the dot operator to access a member of a specific object.

Namespaces and Class Hierarchies

Midterm Exam 5 April 20, 2015

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

CSCE Practice Midterm. Data Types

Object oriented programming

Module 7 b. -Namespaces -Exceptions handling

pointers & references

Object oriented programming

CSCI 111 First Midterm Exam Spring Solutions 09.05am 09.55am, Wednesday, March 14, 2018

Ch 6. Functions. Example: function calls function

1.124 Quiz 1 Thursday October 8, 1998 Time: 1 hour 15 minutes Answer all questions. All questions carry equal marks.

Polymorphism CSCI 201 Principles of Software Development

CMSC 202 Midterm Exam 1 Fall 2015

Problem Solving: Storyboards for User Interaction

Programming in C++ The manager of a company. Lecture Notes 6. Functions (Procedures) 4/24/2018. he he he. Does Does Does

1.124 Quiz 1 Thursday October 8, 1998 Time: 1 hour 15 minutes Answer all questions. All questions carry equal marks.

Friend Functions, Inheritance

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

UEE1303(1070) S12: Object-Oriented Programming Operator Overloading and Function Overloading

Programming. C++ Basics

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS;

G52CPP C++ Programming Lecture 18. Dr Jason Atkin

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

Programming Assignment 3

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

CMPS 221 Sample Final

Due Date: See Blackboard

Linked List using a Sentinel

CS 247: Software Engineering Principles. ADT Design

Today in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout)

for (int i = 1; i <= 3; i++) { do { cout << "Enter a positive integer: "; cin >> n;

SFU CMPT Topic: Has-a Relationship

G52CPP C++ Programming Lecture 18

Topics. bool and string types input/output library functions comments memory allocation templates classes

CSCI 101L - Data Structures. Practice problems for Final Exam. Instructor: Prof Tejada

True or False (15 Points)

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:

Faculty of Science, Engineering and Technology

Time(int h, int m, int s) { hrs = h; mins = m; secs = s; } void set(int h, int m, int s) { hrs = h; mins = m; secs = s; }

Overloading Operators in C++

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std;

File I/O Christian Schumacher, Info1 D-MAVT 2013

Comp151. Generic Programming: Container Classes

CMPE110 - EXPERIMENT 1 * MICROSOFT VISUAL STUDIO AND C++ PROGRAMMING

ECE 461 Fall 2011, Final Exam

True or False (12 Points)

Do not turn to the next page until the start of the exam.

1. Which of the following best describes the situation after Line 1 has been executed?

Due Date: See Blackboard

1. Word Analysis: (Which nouns suggest a need for memory (a variable) and which verbs suggest a need for action (a function maybe).

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

C++ STREAMS; INHERITANCE AS

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

Due Date: See Blackboard

Class Sale. Represents sales of single item with no added discounts or charges. Notice reserved word "virtual" in declaration of member function bill

C C C C++ 2 ( ) C C++ 4 C C

As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board.

G52CPP C++ Programming Lecture 14. Dr Jason Atkin

Lab01: C++ Expressions ES036a: Programming Fundamentals Fall 2007

Object oriented programming

CPSC 427: Object-Oriented Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I.

C++ For Science and Engineering Lecture 12

Introduction to Programming EC-105. Lecture 2

Lecture 23: Pointer Arithmetic

System Design and Programming II

EP241 Computing Programming

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Programming Language. Functions. Eng. Anis Nazer First Semester

EE 109 Lab 8a Conversion Experience

Due Date: See Blackboard

C++ basics Getting started with, and Data Types.

CSCS 261 Programming Concepts Exam 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

1 #include <iostream> 2 using namespace std; 3 4 // implementing the dynamic List ADT using Linked List 5 6 class Node{ 7 8 private: 9 int data; 10

Chapter 4: Subprograms Functions for Problem Solving. Mr. Dave Clausen La Cañada High School

Solving a 2D Maze. const int WIDTH = 10; const int HEIGHT = 10;

Transcription:

Laboratory 7 Programming Workshop 2 (CSCI 1061U) Faisal Qureshi http://faculty.uoit.ca/qureshi C++ Inheritance Due back on Saturday, March 25 before 11:59 pm. Goal You are asked to create a commandline-based interactive program that allows users to add two types of shapes: triangles and circles. The program also allows the user the print the list of stored shapes. Furthermore, it allows the user to modify the stored shapes. Sample run of this program The following run illustrates the interactions supported by this program../lab7 : a == You selected a triangle. == Enter position: 0 0 Enter width and height: 1 2 : b == You selected a circle. == Laboratory 7 - CSCI 1061U 1 of 6

Enter position: 10 2 Enter radius: 1 : a == You selected a triangle. == Enter position: 3 4 Enter width and height: 1 22 : p [0] Triangle location: (0, 0) width and height: (1, 2) [1] Radius location: (10, 2) radius: (1) [2] Triangle location: (3, 4) width and height: (1, 22) : 1 Enter position: 11 3 Enter radius: 1000 : p [0] Triangle location: (0, 0) width and height: (1, 2) [1] Radius location: (11, 3) radius: (1000) [2] Triangle location: (3, 4) width and height: (1, 22) Laboratory 7 - CSCI 1061U 2 of 6

: q Some specifics If user enters a, the programs prompts the user for information about a triangle (position x, position y, width, and height). If user enters b, the programs prompts the user for information about a circle (position x, position y, radius). If user enters p, the program prints the shapes (their types, position x, position y, and other info, e.g., width and height in case of triangles). The program can store up to 10 shapes. If user presses 0-9 the shape stored at that index allows user to re-enter the values (e.g., position x, position y, and radious for circle). Source Code Please complete the Tri and Cir classes in the code below: main #include <iostream> using namespace std; class Point int x, y; Point() Point(int x, int y) this->x = x; this->y = y; friend ostream& operator<<(ostream& os, const Point& pt) os << "(" << pt.x << ", " << pt.y << ")"; return os; ; class Shape // FEEL FREE TO CHANGE THE THIS CLASS // AS LONG AS YOU DON'T HAVE TO CHANGE THE // CONTENTS OF MAIN() AND // PRINT_SHAPES() FUNCTIONS protected: Point _location; Shape() Shape(const Point& location) : _location(location) ~Shape() Laboratory 7 - CSCI 1061U 3 of 6

void draw() cout << "location: " << _location << endl; void get_info_from_user() cout << "Enter position: "; cin >> _location.x >> _location.y; ; // YOU NEED TO COMPLETE THIS CLASS class Tri protected: int _width, _height; // TODO... ; // YOU NEED TO COMPLETE THIS CLASS class Cir protected: int _radius; // TODO... ; ///////////////////////////////////////////////// // // DO NOT CHANGE CODE BELOW THIS LINE // ///////////////////////////////////////////////// #define MAX_SHAPES 10 void print_shapes(shape** shapes, int n) for (int i=0; i<n; ++i) cout << "[" << i << "] "; shapes[i]->draw(); int main() Shape* shapes[max_shapes]; int n = 0; char shape_choice; do cout << "" << endl; cout << "\t" << endl; cout << "\t" << endl; cout << "\t" << endl; Laboratory 7 - CSCI 1061U 4 of 6

cout << "\t" << endl; cout << "\t" << endl; cout << ": "; cin >> shape_choice; if (shape_choice == 'q') switch(shape_choice) case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': shapes[((int) shape_choice) - 48]->get_info_from_user(); case 'a': if (n >= MAX_SHAPES) cout << "== Cannot add any more shapes ==" << endl; continue; cout << "== You selected a triangle. ==" << endl; shapes[n] = new Tri(); shapes[n]->get_info_from_user(); ++n; case 'b': if (n >= MAX_SHAPES) cout << "== Cannot add any more shapes ==" << endl; continue; cout << "== You selected a circle. ==" << endl; shapes[n] = new Cir(); shapes[n]->get_info_from_user(); ++n; case 'p': print_shapes(shapes, n); case 'q': default: cerr << "== Invalid choice ==" << endl; while (true); for (int i=0; i<n; ++i) delete shapes[i]; Laboratory 7 - CSCI 1061U 5 of 6

Submission Please submit via Blackboard Laboratory 7 - CSCI 1061U 6 of 6