Thursday, June 30, 2011

Tuesday, June 28, 2011

First Long Quiz on OOP Concepts Using C++

Dear Class, we will have a very long quiz next week on Object-oriented Concepts using C++.

Section DS1: July 5, 2011
Section C2S/C2S.1: July 6, 2011

First Part: Closed Notes
Second Part: Open Book

Study from the very beginning...

Thursday, June 23, 2011

Guidelines for Laboratory 1: LogBook Abstract Data Type (ADT)

Note: This is only for my laboratory class.

Download the manual for Laboratory 1: LogBook ADT.

Laboratory 1 will be done with at most 3 members. Prepare a one-page report by submitting your work. You will be handing (1) a one-page report of your work, (2) the printed COVER SHEET found in your laboratory manual, and (3) the SOURCE CODE. Fill up the cover sheet of the name of the members that was assigned to them and the status of their work. As usual, NO COPYING since every member is given a certain task. The deadline for this will be on Friday, July 1, 2011, 3PM.

NO LATE SUBMISSION WILL BE ACCEPTED.

Fraction Example

Here is an example of the partial Fraction ADT. Unzip MyFraction.zip and open it in Code::Blocks.

This assignment will be done in pairs.  Just look for your partner and prepare a one-page report. No duplicate work. Deadline for this homework will be on Monday, June 27, 2011, 3PM. See me in my office or leave it on my table.

NO LATE SUBMISSION WILL BE ACCEPTED.

Wednesday, June 15, 2011

Announcement: C2S, C2S.1

To all students  (Sections C2S and C2S.1):

I would like to inform everybody that our classes every WF 1:30-3:00PM will be moved to WF 1:00-2:30PM. Please come ON TIME.

Please inform me if you have problem with the new schedule. You can add our Facebook account.

Cyrus Gabilla / CSc 121 INSTRUCTOR

Announcement: Class Facebook

I would like to inform everybody that the class has a Facebook account. We could use Facebook to raise questions and other matter regarding about the course. Please add if you are interested.

Click HERE to visit the group.

Monday, June 13, 2011

Lecture 2/Reading Assignment: OOP in C++

As a part of the course, you must read the following materials in order to fully understand the concept of the object-oriented programming. Every details in OOP will not be discussed in the class.

1. Introduction to OOP Concepts I and here (pdfs)
4. Introduction to OOP Concepts IV (OpenOffice file/sxi)

Download Foxit Reader to view a .pdf file format and OpenOffice to open a .sxi file format.

Sunday, June 12, 2011

Homework 3: OOP in C++ (100 points)

1. Write a class Fraction which defines adding, subtracting, multiplying, and dividing fractions by overloading standard operators for these operations. Write a function member for reducing factors and overload I/O operators to input and output fractions.

2. Write a driver program to test your class.

----

A fraction number is the ratio of two integers and is typically represented in the manner a/b. The basic arithmetic operations have the following definitions:

Refer to this link on how to operate on fractions.


Reducing a fraction involves finding the Greatest Common Divisor, and then dividing all the terms by that amount.

Euclid’s Algorithm:
if x < y, then swap x and y
While y is not zero
  remainder = x mod y
  x = y
  y = remainder

When you’re done, x is the GCD.


----

//In fraction.h
class Fraction {
    public: // member functions
        // default constructor
        Fraction();

        // a second constructor
        Fraction(int number, int denom=1);

        // destructor
        ~Fraction();

        // copy constructor
        Fraction(const Fraction &r);

        // member assignment
        Fraction& operator=(const Fraction &r);
        // can it be: void operator=(const Fraction &r); ?????


        // some arithmetic and stream facilitators
        Fraction Add(const Fraction &r) const;
        Fraction Sub(const Fraction &r) const;
        Fraction Multiply(const Fraction &r) const;
        Fraction Divide(const Fraction &r) const;
        void Insert(ostream &sout) const;
        void Extract(istream &sin);

    protected:
        // inspectors
        int GetNumerator() const;
        int GetDenominator() const;

        // mutators
        void SetNumerator(int numer);
        void SetDenominator(int denom);

    private:
        // data members
        int NumeratorValue;
        int DenominatorValue;
};
// Fraction ADT: auxiliary operator description
Fraction operator+(const Fraction &r, const Fraction &s);
Fraction operator-(const Fraction &r, const Fraction &s);
Fraction operator*(const Fraction &r, const Fraction &s);
Fraction operator/(const Fraction &r, const Fraction &s);

ostream& operator<<(ostream &sout, const Fraction &s);
istream& operator>>(istream &sin, Fraction &r);
// can they be: void operator<<(ostream &sout, const Fraction &); ?????

//In fraction.cpp
<insert your answer here...>

//In driver_program.cpp
...
int main() {
    Fraction r;
    Fraction s;
    cout << "Enter 1st rational number (a/b): ";
    cin >> r;
    cout << "Enter 2nd rational number (a/b): ";
    cin >> s;
    Fraction tr(r);
    Fraction ts = s;
    Fraction tts;
    tts = s;
    ts = tts = r;
    Fraction Sum = r + s;
    Fraction Difference = r - s;
    Fraction Product = r * s;
    Fraction Ratio = r / s;
    cout << r << " + " << s << " = " << Sum << endl;
    cout << r << " - " << s << " = " << Difference << endl;
    cout << r << " * " << s << " = " << Product << endl;
    cout << r << " / " << s << " = " << Ratio << endl;
    return 0;
}

Friday, June 10, 2011

Homework 2: The Game of Life in C++ (100 points)

Complete the code snippets of "The Game of Life" found in the Lecture 1 transparency.

To run the c++ source codes, download the Code::Blocks Integrated Development Environment (IDE).

Submit the working code in C++. Include sample configurations and generations at most the level of 5.

Printed source code and a sample output in a short bond paper, courier new, 10 points, will only be accepted.


Tuesday, June 7, 2011

Homework 1: The Game of Life (100 points)

Rules for the Game of Life

Life is really a simulation, not a game with players. It takes place on an unbounded
rectangular grid in which each cell can either be occupied by an organism or not.
Occupied cells are called alive; unoccupied cells are called dead. Which cells are
alive changes from generation to generation according to the number of neighbor-
ing cells that are alive, as follows:

1. The neighbors of a given cell are the eight cells that touch it vertically, horizontally or diagonally.
2. If a cell is alive but either has no neighboring cells alive or only one alive, then
in the next generation the cell dies of loneliness.
3. If a cell is alive and has four or more neighboring cells also alive, then in the
next generation the cell dies of overcrowding.
4. A living cell with either two or three living neighbors remains alive in the next
generation.
5. If a cell is dead, then in the next generation it will become alive if it has exactly
three neighboring cells, no more or fewer, that are already alive. All other dead
cells remain dead in the next generation.
6. All births and deaths take place at exactly the same time, so that dying cells
can help to give birth to another, but cannot prevent the death of others by
reducing overcrowding; nor can cells being born either preserve or kill cells
living in the previous generation.

A particular arrangement of living and dead cells in a grid is called a configuration.
The preceding rules explain how one configuration changes to another at each
generation.

Implement the "The Game of Life" in your programming language of choice.

Please try the following simple life configurations: