Você está na página 1de 4

OBJECT-ORIENTED PROGRAMMING

Reference book: OOP by Joyce Farrell, 4th Edition

The Task of Programming

programming a computer involves writing instructions that enable

- the rules of language make up its syntax


- when you write programs, you write program statements that are
instructions that are similar to English-language statements.
- a machine language is the language that computers can understand; it
consists of 0’s and 1’s.
- logical error occurs when you use a statement that, although
syntaticallly correct, doesn’t do when you intended.

Programming Universals
output- the information produced by a program
input – the data provided by an outside source, such as keyboard, scanner
or file.
variables – is also an object although it is a much simpler object than a
monitor or file.

*Overview of Object- Oriented Programming*


Basic Principles behind using Object-oriented programming techniques
involved.
 Objects
 Classes
 Inheritance
 Polymorphism

Object – is anything or is a specific item that belongs to a class


Class- consists of a category of things.
Inheritance – the concept of using classes provides a useful way to organize
objects; it is especially useful because classes are reusable. that is, you can
extend them – they are extensible. You can create new classes that extend
or are descendents of existing classes. the descendent classes can inherit all
the attributes of the original (or parent) class, or they can override
inappropriate attributes.
example: a cube is a descendent of a square
Polymorphism – is the process to carry out the same operation in a
manner customized to the object, such differentiation is never allowed in
languages that are not object oriented.

Using Libraries, Preprocessor, Directives and Namespace


In the early 1990’s, a joint committee of the American National Standards
Institute (ANSI) and International Standard Organization (ISO) Standardized
the syntax used in C++, also known as the ANSI/ISO Standard.

Preprocessor directive – a statement that tells a program, called


preprocessor, what to do before compiling the program. In C++, all
preprocessor directives begin with a pound sign (#), also called as
octothorp.
The # include preprocessor directive tells the compiler to include a file
as part of the finished product.

Producing C++ Output


cout – simplest object pronounced as “see out”, it came from console OUT
and COUT shows whatever is passed to it.
example:
cout <<Hi there;

(<<) – the insertion operator, says “insert whatever is to my right into the
object cout.

/*Program that displays “ Hi there!” using ANSI/ISO C++ Compiler*/

#include<iostream>
using namespace std;
int main()
{
cout<< Hi! there!”;
return (0);
}
/*using a standard C++ compiler */
#include <iostream.h>
int main()
{
cout << “ Hi There !;
return (0);
}

Providing C++ Input


CIN – pronounced “see in”- object fetches values from the keyboard; it is
used with the extraction operator (>>)
example:

#include<iostream>
using namespace std;
int main()
int age;
cout <<” How old are you?”;
cin >> age;
cout << “Your age is “<< age <<endl;
return (0);

similarly to how a single cout object can display multiple values, one cin
object maybe used to enter more than one value,

ex:
int score1, score2,score3;

cout <<”Please enter three scores, use a space between them”;


cin>>score1>>score2>>score3;

Evaluating C++ Expressions


using C++ Binary Arithmetic Operations
1. The addition operator (+)
2. The subtraction operator (-)
3. The multiplication operator (*)
4. The division operator (/)
5. The modulus operator (%)
Exercises:
1. Make a c++ program in which you declare a variable that holds an
hourly wage. Prompt the user to enter an hourly wage. Multiply the
wage by 40 hours and print the standard weekly pay.
2. Make a program will ask the user to enter distance in meter and
output the equivalent distance in centimeter.

Você também pode gostar