Homework #3: Classes and Constructors

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Programming With Java ICS201 University Of Hail1 Chapter 13 Inner Classes.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
CSCI 160 Midterm Review Rasanjalee DM.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
C++ Classes & Data Abstraction
Homework #2: Functions and Arrays
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Overview 10.1 Structures 10.2 Classes 10.3 Abstract Data Types.
Eiffel examples. Example 1 class C creation default_create feature {ANY} -- the public class data count: INTEGER element: DOUBLE end; features - the data.
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
Tutorial 6 February 4th/5th, 2015
1 Lab Session-8 CSIT-121 Fall 2003 w Call by Reference w Lab Exercise 1 w Lab Exercise for Demo w Practice Problems.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
CS 117 Spring 2002 April 5, Exam 3 April 10 –files, arrays, strings, classes –practice exams are up –review on Monday.
Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 1 Overview – Chapter Section 4 Arrays and Classes (10.4)
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
1 Project 5: Median. 2 The median of a collection of numbers is the member for which there are an equal number less than or equal and greater than or.
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
Class & Object 蔡柏灃.
While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.
Homework #3: Classes and Constructors
Homework #4: Operator Overloading and Strings By J. H. Wang May 8, 2012.
Java Review I. What is a stream? What is a byte stream? what is a character stream? What types of files does a program will typically handle?
Homework #5: Pointers, Dynamic Arrays and Inheritance
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
11 Introduction to Object Oriented Programming (Continued) Cats.
CS 210 DATA STRUCTURES AND ALGORITHIMS Fall 2006.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft RAM Allocation Chapter 3.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
Homework #2: Functions and Arrays By J. H. Wang Mar. 20, 2012.
Homework #1: C++ Basics, Flow of Control, and Function Basics By J. H. Wang Mar. 13, 2012.
Lab 1 Logbook ADT. OVERVIEW A monthly logbook consists of a set of entries, one for each day of the month.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 9: Continuing with classes.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
1 CS161 Introduction to Computer Science Topic #8.
Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009.
Project 3: Ticket Printer
Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014.
Homework #1: C++ Basics, Flow of Control, and Function Basics
Homework #3: Classes and Constructors By J. H. Wang Apr. 14, 2014.
Homework #4: Operator Overloading and Strings By J. H. Wang May 12, 2014.
Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang Jun. 5, 2009.
1 Mr. Muhammad Hanif Lecturer Information Technology MBBS Campus Dadu University of SIndh.
The for loop.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang May 31, 2011.
Homework #2 J. H. Wang Mar. 29, Homework #2 Chap.3 –3.5 (a) –3.8 (b) –3.16 –3.23 (a)
Struct s (7.4) Used as data aggregates for an entity can be different types of data e.g. for student id, name, GPA, address,... Similar to classes, but.
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
Constructors, Copy Constructors, constructor overloading, function overloading Lecture 04.
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 7, Feb 6/7, 2013.
14 BirthMonth1February BirthMonth CE : Fundamental Programming Techniques.
Homework #3: Classes and Constructors By J. H. Wang Apr. 24, 2015.
Exercise 6 Introduction to C# CIS Create a class called ParseDates that will parse a formatted string containing a date into separate integers.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
Homework #4: Operator Overloading and Strings By J. H. Wang May 22, 2015.
100 學年度碩士班新生暑期課程 程式設計 Object-Oriented Programming: Part I The Basics of Classes.
Chapter 1 Connections to Algebra Review
Examples of Classes & Objects
Auburn University COMP 3000 Object-Oriented Programming for Engineers and Scientists Structures Cont. Dr. Xiao Qin Auburn.
HKCT Java OOP Unit 02 Object Oriented Programming in Java Unit 02 Methods, Classes, and Objects 1.
Classes & Objects: Examples
Constructors and Destructors
CSC 111 Exam 3 Review Fall 2005.
CS 201(Introduction To Programming)
Presentation transcript:

Homework #3: Classes and Constructors By J. H. Wang Apr. 19, 2011

Part I: Hand-Written Exercises 1. Suppose your program contains the following class definition (along with definitions of the member functions): class YourClass { public: YourClass(int newInfo, char moreNewInfo); YourClass(); void doStuff(); private: int information; char moreInformation; }; (To be continued on the next slide…)

(…continued from the previous slide) Which of the following are legal? For illegal ones, please explain the reasons why they are illegal. (a) YourClass anObject(42, ‘A’); (b) YourClass anotherObject; (c) YourClass yetAnotherObject(); (d) anObject = YourClass(99, ‘B’); (e) anObject = YourClass(); (f) anObject = YourClass;

2. (1) Explain what public: and private: mean in a class definition. (2) When you define a C++ class, should you make the member variables public or private? Should you make the member functions public or private? Please explain the reasons why. 3. What is a default constructor? Does every class have a default constructor?

Part II: Programming Exercises 4. Define a class for a type called CounterType. An object of this type is used to count things, so it records a count that is a nonnegative integer. Include the following member functions: (1) a function that sets the counter to a count given as an argument, (2) functions that increase the count by one and decrease the count by one. Be sure that no member function allows the value of the counter to become negative or out of range for nonnegative whole numbers, (3) a function that returns the current count value, and (4) a function that outputs the count. Embed your class definition in a C++ test program.

5. Define a class for a type called Month that is an abstract data type for a month. Your class will have one member variable of type int to represent a month (1 for January, 2 for February, and so forth). Include all the following member functions: (1) a constructor to set the month using the first three letters in the name of the month as one string argument (“JAN” for January, “FEB” for February, and so forth), (2) a constructor to set the month using an integer as an argument (1 for January, 2 for February, and so forth), (3) a default constructor, (To be continued on the next slides…)

(… continued from the previous slides) (4) an input function that reads the month as an integer, (5) an input function that reads the month as the first three letters in the name of the month, (6) an output function that displays the month as an integer, (7) an output function that displays the month as the first three letters in the name of the month, (8) and a member function that returns the next month as a value of type Month. Embed your class in a C++ test program.

Homework Submission Due: 2 weeks (May 3, 2011) Hand-written exercises Please write your name and answers on papers Programs Please submit to http://140.124.183.39/oop/ File names: Please name your file according to our homework. For example, HW1.zip or quiz2.rar

Any Questions?