Announcements Homework 3 – Robot game will be assigned this Friday

Slides:



Advertisements
Similar presentations
Operator Overloading Fundamentals
Advertisements

Announcements Homework 4 – Robot game is assigned Due NEXT WEEK on Wednesday 26 th November  Start EARLY! Common Questions: Be aware of the flow of the.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
CS201 – Introduction to Computing – Sabancı University 1 Announcements l General rules about homeworks ä Use of global variables (variables defined outside.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Announcements Midterm is TOMORROW! On August 2 nd Tuesday at 19:40 (~ 100 minutes) in FENS L045 Today at 14:30-17:30 there is an extra recitation in FENS.
CS201 – Introduction to Computing – Sabancı University 1 Announcements l General rules about homeworks ä Use of global variables (variables defined outside.
CCSA 221 Programming in C CHAPTER 14 MORE ON DATA TYPES 1 ALHANOUF ALAMR.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Announcements HW3 grades will be announced this week HW4 is due this week Final exam on August 25, 2010, Wednesday at 09:00 Duration is about 140 minutes.
Using, Understanding, Updating, Designing and Implementing Classes Chapters 5 (5.4) and partially 6 and 7 in Chapter 6, up to in Chapter 7 concepts.
1 Advanced Issues on Classes Part 3 Reference variables (Tapestry pp.581, Horton 176 – 178) Const-reference variables (Horton 176 – 178) object sharing:
Announcements Midterm1 is on this Tuesday at 19:40. Classrooms as follows: if (LastName
CS201 – Introduction to Computing – Sabancı University 1 First Midterm Exam l November 25, 2006, Saturday, 10:40 – 12:20, max 100 minutes l Exam Places.
Summary of what we learned last week Classes How to use classes/objects Header (.h) and implementation (.cpp) files String class Member functions: length,
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
CS201 – Introduction to Computing – Sabancı University 1 Using, Understanding, Updating, Designing and Implementing Classes l Chapters 5 (5.4) and partially.
Manipulator example #include int main (void) { double x = ; streamsize prec = cout.precision(); cout
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.
Announcements HW2 is due on Wednesday this week. HW3 will be assigned this week, will be due next week.
Yan Shi CS/SE 2630 Lecture Notes
EGR 2261 Unit 13 Classes Read Malik, Chapter 10.
EGR 2261 Unit 11 Pointers and Dynamic Variables
Java Language Basics.
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
11 Chapter Structured Data
EGR 2261 Unit 5 Control Structures II: Repetition
Classes and OOP.
Lectures linked lists Chapter 6 of textbook
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Introduction to Pointers and Dynamic Memory Allocation
Announcements HW6 due this Wednesday
Announcements Homework 5 – Robot game will be assigned this week
classes and objects review
Announcements Homework 5 – Robot game will be assigned this week
The dirty secrets of objects
Tuesday, February 20, 2018 Announcements… For Today… 4+ For Next Time…
Announcements 2nd homework is due this week Wednesday (October 18)
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Linked Lists.
Announcements Homework 5 – Robot game will be assigned this week
More on Classes Classes may have constructors which are called when objects are created and destructors which are called when objects are destroyed. Classes.
What’s Left in the Course
Starting JavaProgramming
Using, Understanding, Updating, Designing and Implementing Classes
Announcements Midterm2 Grades to be announced NEXT Monday
Operator Overloading; String and Array Objects
Chapter 5 Function Basics
Chapter 11: Structured Data.
Announcements 3rd homework is due this week Wednesday (March 15)
Announcements HW6 due this Wednesday
Dr. Bhargavi Dept of CS CHRIST
Doubly Linked List Implementation
Announcements Homework 1 will be assigned this week,
Summary of what we learned yesterday
Announcements HW2 is due on Wednesday this week.
Dot the Days Calendar Activity CATHY JONES
Data Structures & Algorithms
Standard Version of Starting Out with C++, 4th Edition
CS 144 Advanced C++ Programming February 21 Class Meeting
Chapter 9 Introduction To Classes
Instructor: Dr. Michael Geiger Spring 2017 Lecture 12: Exam 1 Preview
Class rational part2.
Doubly Linked List Implementation
Announcements HW1 is due TODAY.
四時讀書樂 (春) ~ 翁森 山光照檻水繞廊,舞雩歸詠春風香。 好鳥枝頭亦朋友,落花水面皆文章。 蹉跎莫遣韶光老,人生唯有讀書好。
(4 – 2) Introduction to Classes in C++
Data Structures & Programming
Presentation transcript:

Announcements Homework 3 – Robot game will be assigned this Friday Due in 1.5 WEEKS  Start EARLY! Common Questions: Be aware of the flow of the game, read the document for all details The flow of the game will repeat inside a big while loop until the game ends, we call one run of this loop a “turn” in the document: Do not use TurnRight in TurnFace member function Instead Turn the robot to a given direction by updating the private data member directly that you implemented for this HW in recitations Submit ALL files in your project: main.cpp, robot_modified.cpp, robot_modified.h, minifw_modified.cpp, minifw_modified.h Use the world.rw file in the homework zip to open an example world.

Midterm Grades To be announced NEXT WEEK Tuesday You may see your papers on Wednesday at 15:00-16:30 in FENS L030

Using, Understanding, Updating, Designing and Implementing Classes Chapters 5 (5.4) and partially 6 and 7 in Chapter 6, up to 6.2.3 in Chapter 7 concepts of 7.1 and 7.2 are explained, but different examples are given Robot class implementation details

RandGen Class A Tapestry class for random number generation Add randgen.cpp to your project and have #include "randgen.h" in your program Four member functions int RandInt(int max = INT_MAX); returns a random integer in [0..max) int RandInt(int low, int max); returns a random integer in [low..max] double RandReal(); returns a random double value in [0..1) double RandReal(double low, double max); returns a random double value in the range of [low..max] see numberguess.cpp for an example program that use RandGen

Overloading In RandGen class, there are two different functions named RandInt so as RandReal Using the same name for more than one function is called overloading. They are differentiated by parameter types Return types do not differentiate funtions All member and free functions can be overloaded.

Implementation of Robot Class - 1 Your next homework will be about updating the Robot class you will add some new member functions that requires to deal with robots.h and robots.cpp files (actually in the homework, you will use an updated class for which the file names are robots_modified.h and robots_modified.cpp) and you will use those newly added functions in an application It is a good idea to have a look at how this class is implemented It is designed and implemented by Ersin Karabudak We have made some changes later Robot class implementation is quite complex Robot, RobotWindow and RobotWorld are different structures we will not deal with RobotWindow and RobotWorld, but the implementation file contains robot class implementation and the details of RobotWindow and RobotWorld too. Do not get confused. Robots are maintained as a circular doubly linked list it is a data structure that uses pointers (probably will see in CS300) but do not get thrilled! you will not need those complex structures for the member functions that you will add. Some details you have to know will be given now and more details will be given in recitations this week

Implementation of Robot Class - 2 enum Direction { east, west, north, south }; enum Color { white, yellow, red, blue, green, purple, pink, orange }; class Robot { public: Robot (int x, int y, Direction dir = east, int things = 0); ~Robot (); void Move (int distance = 1); bool Blocked (); void TurnRight (); bool PickThing (); bool PutThing (); void SetColor (Color color); bool FacingEast (); bool FacingWall (); bool CellEmpty (); bool BagEmpty (); constructor Destructor (not needed in HW5) member functions continued on the next slide

Implementation of Robot Class - 3 private: int xPos; //x coordinate of the location of robot int yPos; //y coordinate of the location of robot Direction direction; //current direction of robot Color color; //current color of robot int bag; //current # of things in the bag of robot bool stalled; //true if the robot is dead bool visible; //true if the robot is visible Robot *next; Robot *prev; static Robot *list; friend struct RobotWindow; }; Private Data pointers for the data structure you will not need them RobotWindow may refer Robot’s private data

Implementation of Robot Class - 4 Previous two slides were in the robots.h (now robots_modified.h). Now let’s go over the robots.cpp (now robots_modified.cpp) file in VC++ environment In the next homework, you are going to add 6-8 member functions to the robot class Some of the member functions will be done in recitations this week Hints try to use currently available member functions e.g. for PickThings, try to use PickThing in a loop rather than writing some thing similar to PickThing do not hesitate to modify or access private data members when needed e.g. you will need such an update for TurnFace function if you change the state of a robot within the current cell, use the following to update the window theRobotWindow->Redraw(this);

Implementation of Robot Class - 5 Hints for the next homework (cont’d) you will need to use the function called IsPressed defined in miniFW.h (it is going to be renamed as miniFW_modified.h) so include this header file to your main program file this function (IsPressed) is to check whether a key (e.g. an arrow key) is pressed or not - details are in recitations Some other changes in the Robot World and Robot Class If a robot hits another robot, both die! No automatic message is displayed when a robot dies Now the bag content is written in robots (if not zero) Use robots_modified.h, robots_modified.cpp, miniFW_modified.h and miniFW_modified.cpp files in HW5 They will be provided to you in the homework and/or recitation package

The class Date The class Date models a calendar date: The class Date is accessible to client programmers #include "date.h" to get access to the class The compiler needs this information. It may also contain documentation for the programmer Link the implementation in date.cpp Add this cpp to your project The class Date models a calendar date: Month, day, and year make up the state of a Date object Dates can be printed, compared to each other, day-of-week determined, # days in month determined, many other behaviors Behaviors are called methods or member functions

Constructing Date objects – see usedate.cpp Date today; Date republic(10,29,1923); Date million(1000000); Date y2k(1,1,2000); cout << "today: " << today << endl; cout << "Republic of Turkey has been founded on: " << republic << endl; cout << "millionth day: " << million << endl; OUTPUT today: April 4 2016 Republic of Turkey has been founded on: October 29 1923 millionth day: November 28 2738

Constructing/defining an object Date objects (as all other objects) are constructed when they’re first defined Three ways to construct a Date default constructor, no params, initialized to today’s date single long int parameter, number of days from January 1, 1 three params: month, day, year (in this order). Constructors for Date objects look like function calls constructor is a special member function Different parameter lists mean different constructors Once constructed, there are many ways to manipulate a Date Increment it using ++, subtract an integer from it using -, print it using cout, … MonthName(), DayName(), DaysIn(), … See date.h for more info on date constructors and member functions

Date Member Functions Date MidtermExam(27,3,2017); Construct a Date object given month, day, year MidtermExam.DayName() Returns the name of the day (“Monday” or “Tuesday”, or ...) in this particular case, returns “Monday” since December 1, 2014 is a Monday MidtermExam.DaysIn() Returns the number of days in the particular month in our case return 31, since March 2017 has 31 days in it Add, subtract, increment, decrement days from a date Date GradesDue = MidtermExam + 9; GradesDue is April 5, 2017 Let’s see usedate.cpp in full and datedemo.cpp now

Example: Father’s day (not in book) Father’s day is the third Sunday of June write a function that returns the date for the father’s day of a given year which is the parameter of the function In main, input two years and display father’s days between those years Date fathersday(int year) // post: returns fathers day of year { Date d(6,1,year); // June 1 while (d.DayName() != "Sunday") d += 1; } //d is now the first Sunday, 3rd is 14 days later return d + 14; See fathersday.cpp for full program

What if there were no date class? It would be very cumbersome to deal with dates without a date class imagine banking applications where each transaction has associated date fields Classes simplify programming they are designed and tested. then they can be used by programmers You are lucky if you can find ready-to-use classes for your needs otherwise ???

Updating a Class (not in book) Suppose you want to add more functionality to the date class need to change the header file (date.h) need to add implementation of new function(s) to date.cpp Example: a new member function to calculate and return the remaining number of days in the object’s month any ideas? do you think it is too difficult? have a look at the existing member functions and see if they are useful for you

Updating a Class (not in book) We can make use of DaysIn member function Prototype in Date class (add to the header file) int RemainingDays () const; Implementation int Date::RemainingDays () const { return DaysIn() - myDay; } In a member function implementation private data and other member functions referred without the dot operator. They operate on the object for which the member function is called