0% found this document useful (0 votes)
22 views

Programming Fundamentals Lec1

The document discusses computers, programming, and the C++ programming language. It defines a computer as an electronic device that takes input, processes it, stores it in memory, and outputs the results according to given instructions called programs. Programming is the technique of writing programs, which is both an art and a science. The C++ programming language uses preprocessors, keywords, libraries, and output functions to write programs that are then compiled or interpreted into machine-readable code.

Uploaded by

Natalia khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Programming Fundamentals Lec1

The document discusses computers, programming, and the C++ programming language. It defines a computer as an electronic device that takes input, processes it, stores it in memory, and outputs the results according to given instructions called programs. Programming is the technique of writing programs, which is both an art and a science. The C++ programming language uses preprocessors, keywords, libraries, and output functions to write programs that are then compiled or interpreted into machine-readable code.

Uploaded by

Natalia khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

WHAT IS COMPUTER?

Any electronic device that take input, process it and also store it in memory and in the last stage give us the output
of our given input is called computer.

“ACCORRDING TO OUR GIVEN INSTRUCTIONS”


&
these instructions are called programs.

WHAT IS PROGRAM?
Programs Are The Instructions That We Give/Write Computer To Perform Any Specific Task Is Called Program.
Computer cannot understand our language so if we want to solve any task with the help of computer we need to
write a program.

WHAT IS PROGRAMMING?
Programming is a technique used to write any program.

&

“Programming is Art and Science”

ART: Programming have different & creative ways to write any program.

SCIENCE: Programming have some rules to follow.

If we want that computer perform any task that we want we have to write a program with techniques that is called
programming.

PROGRAMMING LANGUAGES:
Now we have to talk about the Source of Communication to Computer that is called programming languages.

There ae two type of Programming languages:

 Low-level languages:
1. Near to computer.
2. Deep knowledge of hardware is required.
3. Easily to understandable for hardware but it is difficult for programmers to write any program.

 Machine Language:
1. Actually consist on Binary numbers that is difficult and not modifiable for programmers.
2. Deep knowledge of hardware is required.
3. Difficult to write or read, Debug or troubleshoot program.
 Assembly Language:
1. Consist on Mnemonics (Symbolic Codes).
2. Short codes that have binary no in backend. Like: move (111111111011).
3. Now the code is readable, modifiable and easy foe programmers.
 High-level language:
1. English like language.
2. Near and understandable for humans and far from computer.
3. In High-level language it is too easy to write program for programmers but difficult for computers to
understand so we need processors (translators) that convert source code(high-level language) into object
code(Machine language).

Language Translators:
 Assembler:
A translator or processor that convert assembly language into machine language.

 Compiler:
A translator that converts whole statement of High-level language into machine language.

 Interpreter:
A translator that converts single line statement one time of high-level language into machine language.

BUGS IN PROGRAMS (ERRORS):


 SYNTAX ERROR:
Violation of rules of whatever programming language it is, easy to find because during execution compiler
highlight the syntax errors.
Those errors or mistakes that we do when we are writing the programs are called syntax errors.
i.e:
Wrong syntax: print(hello world)
Right syntax: printf(“hello world”);

 RUNTIME ERROR:
That occur during execution or when the given instruction is out of range of computer, computer does not
execute the program.

 LOGICAL ERRORS:
That occur when we do error in planning our program logic, difficult error to find.

IDE (Integrated Development Environment) AND


STRUCTURE OF C++:
When we are writing any program, we need a software that allow us to write a program, modify it, translate it in
machine language, save the source code file and correct errors. This software called IDE that provide us these
facilities. IDE have two interfaces(screens):

1. Editor: where we write our program or edit it.


2. Console: Screen where the output is generated.

STRUCTURE OF C++ PROGRAM:


1. Libraries: “means that contain information”. In IDE libraries also called header files that have information
about reserves, functions are called Libraries of C++. Mostly libraries are in the form of files or namespace. If
the library is in the form of file, then the extension will be(.h)
2. Namespace: A namespace is a declarative region that provides a scope to the identifiers (the
names of types, functions, variables, etc) inside it.
3. Main function:
 Body {}
 Statement terminator (;)

#include<iostream.h> ----------------------------------------------------------------- header


Void main()------------------------------------------------------------------------------- header
{--------------------------------------------------------------------------------------------- body start
Clrscr();
Cout<<my name is natalia;
Getch();
}---------------------------------------------------------------------------------------------Body ends

PRE-PROCESSOR DIRECTIVES:
Every directive is a one-line long command which contains the following: # (hash) symbol (All
the preprocessor directives in C++ start with the # (hash) symbol). A pre-processor instruction after
the # (hash) symbol. For example, #include, #define, #ifdef, #elif, #error, #pragma etc.
As its name shows pre-process means before the compilation of program pre-processor directives are added
to our program. There are two type of pre-processor directives:
#include: to include any other file or library to your program.
Syntax:
#include<stdio.h>-------------------------angle brackets if we are adding a file that is
provided by our IDE or compiler (when we download c++ IDE the folder include is created and all the pre-
made library or file or functions is saved on that folder) like: <iostream>, <stdio.h>, <conio.h>
#include” myfile.h” -----------------------------------------double quotes if we are using the file or library that we
created.
#define: use to create macros like:
Syntax: #define five 5 .the value of five is 5, means that in my program replace every word five with 5.

KEYWORDS IN C++:
Keywords are the pre-defined words in a language that have some specific meaning. According to structure C
language have 30 pre-defined keywords in it and now C++ have 90 keywords in it.

KEYWORDS LIKE: int, float, string, short, long, double, char.

If, else, switch, default, case, break.

For, while, do
RESERVED WORDS IN C++:
Now if we talk about reserved words we can say that the reserve words are not the part of programming language or
c++ but it is the part of header or library.

Like if we have a reserved word “string” that is defiened in library “namespace std”

DISTINGUISH B/W KEYWORDS AND RESERVED


WORDS:

Keywords Reserved words


Keywords are not pre-defined in the programming Reserved words can be pre-defined.
language.
Not necessary to add any library file in the header.it Necessary to add library file (bc reserved words are
is directly understandable for programming language pre-defined in it) in the header otherwise reserved
words are not understandable by programming
language.

OUTPUT FUNCTIONS:
Output functions are those functions that help us to print any statement on console (output) screen. There
are too many output functions in c++.
1. Printf:
use in C. As its name shows print function it is pre-defined in stdio (standard input output) library.
SYNTAX:
Printf(“hello world”) no matter what we write in these double quotes will be printed on the
console screen except Escape sequence and format specifiers.
2. Cout:
use in C++. The most popular way to print statement it is pre-defined in iostream library
SYNTAX:
Cout<<”hello”;
These << means stream insertion operator in fact in our programming language we have a library/
header file iostream, & in iostream this operator(<<) is overload or added. Means that left operands
Is cout and operator is << and right operand is any message that we want to print.
3. cprintf:
Color print function is help you to add colors on the console screen it is pre-defined in conio library.
SYNTAX: OUTPUT:
Textbackground(black); hello
Textcolor(red);
Cprintf(“hello”);
TRICKS:
YOU CAN USE YOUR NAME OR ANY WORD INSTEAD OF COUT AND IT WILL WORK AS COUT FUNCTION
LETS SEE HOW IT WORKS.
Cout function is a reference of ostream class or library (output stream) that is pre-defined in our compiler
means that ostream &cout is already have a reference with each other in our language. Yani jab bhi ham
cout likh kar kuch bhi print karwatey hen tou pata chalta hey key cout bhi aik ostream jesi hi chezz hey jisko
ham changing karke use karskte hen.

HOW TO USE COUT IN OUR WORDS?


SOURCE CODE: OUTPUT:
#include<iostream> hello
Using namespace std;
Int main()
{
Ostream &natalia=cout;
Natalia<<”hello”;
}

VARAIBLES IN C++
Varaiables are the named memory location in RAM which contain some value which can be changed.
Varaibles are the container that contain some values.
SYNTAX:
Datatype varName;

DATATYPE IN C++
Datatype define which of data youre working with. There is different built-in datatypes are provided in our
programming language.

You might also like