CS112_44_Assignment6B - CS112 Assignment 6B Solitaire Due:...

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

View Full Document Right Arrow Icon
CS112 Assignment 6B – Solitaire Due: June 12 An object-oriented approach In this assignment, the implementation you will write moves you in the direction of "objectoriented" programming. Although C is not inherently an object-oriented language, we can use it to see what this type of programming is all about. If you think about how you have written programs up to now, you have generally concentrated on the algorithms that perform the necessary steps, and how to decompose those algorithms into parts. In the object-oriented approach, we decompose the problem into a set of objects that make sense in the problem domain. These objects operate as somewhat autonomous agents that interact and collaborate to achieve the overall goal of the program. Each object has its own behavior, and each models some aspect of the real world. The first question we have to ask is this: what, in a programming sense, is an object? The answer is that an object is an entity that has a state and behavior. The rest of the program interacts with the object by sending it "messages", which ask about its state, cause it to change its state, or ask it to behave in a certain way. The knowledge about how to represent the state and carry out the actions is "encapsulated" in the object. Our notion of ADTs captures much of this idea. We provide a data structure, the CDT, and a set of functions (some public and some private) that use the structure. The main difference in the object-oriented approach is that the data and functions are thought of as bound together as parts of the overall structure. In object-oriented terminology, the object has "member variables" that preserve its state and "methods" that carry out its behavior , and both of these are accessed through a pointer to the object. You may now be wondering how we can package data and functions together in C. We can get this effect by using function pointers; if each structure stores pointers to the functions that are appropriate for it, the function pointers end up being very similar to the idea of methods in object-oriented programming. If an object's behavior needs to change, we can replace an existing pointer with a pointer to a function that implements the desired behavior. The application: Klondike In this assignment, your job is to write a program that plays the solitaire game called Klondike, which is almost certainly the best-known solitaire card game in the United States. As an assignment, Klondike has two purposes: 1. It gives you an opportunity to work with list structures in an application that is more interesting than the editor buffer. 2. It anticipates the topic of object-oriented programming, which is a paradigm popular in modern computer science and you will certainly encounter if you continue taking computer science courses. The assignment is designed so that the individual cards take center stage,
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 and the game is organized as operations on cards. Cards, for example, can attach themselves to other cards and respond to being dragged with the mouse. Approaching this problem from the perspective of the cards has two principal advantages. First,
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/06/2010 for the course CS 112 taught by Professor Yinlinwang during the Spring '08 term at Shanghai Jiao Tong University.

Page1 / 22

CS112_44_Assignment6B - CS112 Assignment 6B Solitaire Due:...

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

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