You are on page 1of 10

Chapter One:

1. What is a Computer program?


A Computer program is A set of instructions for a computer to follow, Also
is a list of instructions that tell a computer what to do.

2. What is Computer Software?


• Computer software is The collection of programs used by a computer.
It Includes: Editors, Translators, System Managers.

Computer Vs Human:
• Computers understand a language variously known as computer language or
machine language. It’s possible but extremely difficult for humans to speak
machine language.

• Therefore, computers and humans have agreed to sort of meet in the middle,
using intermediate languages such as C++.

• Humans can speak C++ , and C++ is converted into machine language to
understand the computer

3. Define The Following?


Compilers: Translate high-level language to machine language
Source code: is the original program in a high level language
Object code: is the translated version in machine language, also referred to
as binary code or machine code.

A Linker: combines the objectcode for the programs we write and


the object code for the pre-compiled routines into the machine language
program the CPU can run.

Programming and problem solving:

• Algorithms: is A sequence of precise instructions which leads to a solution


• Program: is An algorithm expressed in a language the computer can
understand. Also is a sequence of instructions to solve a particular problem.
• Programming: is a creative process Complete set of rules for creating a
program.

Program Design Process:


Problem Solving phase: Certain tasks are completely specified
• What is the input?
• What information is in the output?
• How is the output organized?
• Develop the algorithm before implementation
• Experience shows this saves time in getting your program to run and
test the algorithm for correctness.

Implementation phase:
• Translate the algorithm into a programming language
• Compile the source code
• Run the program on sample data
• Results may require modification of the algorithm and the program.
4. What is Object Oriented Programming? Explain its Characteristics?
Object Oriented Programming: Program is viewed as interacting objects
and Each object contains algorithms to describe its behavior.
• OOP Characteristics
1) Encapsulation:
• Information hiding
• Objects contain their own data and algorithms
2) Inheritance:
• Writing reusable code
• Objects can inherit characteristics from other objects
3) Polymorphism:
• A single name can have multiple meanings depending on its context

5. Why Do We Need OOP?


Object-oriented programming was developed because limitations were
discovered in earlier approaches to programming. To appreciate what
OOP does, we need to understand what these limitations are and how
they arose from traditional programming languages.

Classes:
• In OOP we say that objects are members of classes.
• A class is a description of a number of similar objects. Ahmed and Hassan
are members of the musician class.
• There is no one person called “musician” but specific people with specific
names are members of this class if they possess certain characteristics.
• An object is often called an “instance” of a class.
Reusability: if Once a class has been written, created, and debugged, it can be
distributed to other programmers for use in their own programs.

Polymorphism: is Using operators or functions in different ways, depending on


what they are operating on.
Overloaded: is When an existing operator, such as + or =, is given the capability
to operate on a new data type, it is said to be overloaded.

C++ and C:
 C++ is derived from the C language. Strictly speaking, it is a superset of C:
Almost every correct statement in C is also a correct statement in C++.

 The most important elements added to C to create C++ are concerned with
classes, objects, and Object-Oriented Programming. (C++ was originally
called “C with classes.”)

6. What is a C++?
• C++ is an object-oriented Language.
• As an object-oriented language, C++ has the power and extensibility to
write large-scale programs. C++ is one of the most popular programming
languages for all types of programs. Most of the programs you use on your
PC every day are written in C++.

• Testing and Debugging


Bug: A mistake in a program
Debugging: Eliminating mistakes in programs

Program Errors
Syntax errors:
• Violation of the grammar rules of the language
• Discovered by the compiler
• Error messages may not always show correct location of errors
• Run-time errors
• Error conditions detected by the compiler at run-time
• Logic errors
• Errors in the program’s algorithm
• Most difficult to detect
• Compiler does not recognize an error

Difference Between C and C++:

C C++

 Is a procedural language.  Is an OOP language.

 The main function should not return any  The main function should return
value. value.

 The scope of the variable should be declared  The scope of the variable can be
at the beginning of the program. where of the program.

 We need to provide format specifiers to read  There are no format specifiers to


or write a data. data.
Chapter 2
The program statement: is the fundamental unit of C++programming.Most
statements tell the computer to do something. A semicolon signals the end of
the statement.

Directives:
• The two lines that begin the program are directives.
• The first is a preprocessor directive, and the second is a using directive.
• They occupy a sort of gray area: They are not part of the basic C++
language, but they are necessary anyway.
Cout and CIN
• The identifier cout (pronounced “C out”) is actually an object which is
predefined in C++ to correspond to the standard output stream.
• The operator << is called the insertion or put to operator. It directs the
contents of the variable on its right to the object on its left.
• The keyword cin (pronounced “C in”) is an object, predefined in C++ to
correspond to the standard input stream. This stream represents data coming
from the keyboard. The >> is the extraction or get from operator. It takes
the value from the stream object on its left and places it in the variable on its
right.

Comments:
• Comments help the person writing a program, and anyone else who must
read the source file, understand what’s going on. The compiler ignores
comments, so they do not add to the file size or execution time of the
executable program.
• so the comments should concentrate on the big picture, clarifying your
reasons for using a certain statement or group of statements
• In C++, there are two types of comment:
• Single-line comment which begins with // and terminates at the end of the
current line.
• Multi-line comment which begins with /* and ends with */.

Variables:
• A variable is a location in the computer's memory where a value can be
stored for use by a program. When a variable is given a value, that value is
actually placed in the memory space assigned to the variable.
• All variables must be declared with a name and a data type before they can
be used in a program.
• For example, int x;

Constants:
• The keyword constant is used to declare a constant and precedes the data
type of a variable.
For example: const int PI = 3.14;
• It specifies that the value of a variable will not change throughout the
program.

Declarations and Definitions:


• A declaration introduces a variable’s name (such as var1) into a program and
specifies its type (such as int).
 However, if a declaration also sets aside memory for the variable, it is also
called a definition.
C++ Basic Data Types:
• Boolean (bool)
• Short integer (short)
• Character (char)
• Integer (int)
• Long integer (long)
• Real number (float)
• Long real number (double)

Expressions and Statements:


• Any arrangement of variables, constants, and operators that specifies a
computation is called an expression.
• Note that expressions are not the same as statements. Statements tell the
compiler to do something and terminate with a semicolon. There can be
several expressions in a statement.

Manipulators:
• Manipulators are operators used with the insertion operator (<<) to modify
(or manipulate) the way data is displayed.
• setw changes the field width of output. The setw manipulator causes the
number (or string) that follows it in the stream to be printed within a field n
characters wide, where n is the argument to setw(n).
Operators
Rules of Operator Precedence
PEDMAS (Parentheses, Exponents, Division, Multiplication, Addition and
Subtraction).

Arithmetic Assignment Operators


+=, -=, *=, /*, %=
Relational (comparison) Operators
(<, <=, >, >=, ==, !=)
Logical Operators
AND (&&), OR (||), NOT (!)
Increment (++) and decrement (--) operators

Prefix and Postfix:


Increment (or decrement) operator can be used in two ways:
• as a prefix: meaning that the operator precedes the variable and it is
incremented (or decremented) before using it in the statement;
• and as a postfix: meaning that the operator follows the variable and it is
incremented (or decremented) after using it in the statement.

Library Functions:
• Many activities in C++ are carried out by library functions. These functions
perform file access, mathematical computations, and data conversion, among
other things.
• One of the most important library function is sqrt() and is to calculate the
square root of a number that it takes as argument.

You might also like