Nothing Special   »   [go: up one dir, main page]

Getting Started With C: ++ What Is Computer? List The Primary Components of A Computer System

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

GOVERNMENT POSTGRADUATE COLLEGE 1

JHANG
Department of Computer Science

GETTING STARTED WITH C ++

QUESTION NO.01:-What is Computer? List the primary components of a Computer System.


COMPUTER
Computer is an electronic device that converts our data into meaningful
information and gives logistic results. Modern Computer is an electronic
machine that accepts Data/Information from user, stores it into its Memory,
processes that Data/Information
arithmetically and logically
without human intervention and
provides results from that
processing to the outside world.

A Computer System
requires different hardware
components to perform the
functions of input, processing,
output, storage.
PRIMARY COMPONENTS
A list of primary components of a Computer System is:
Input Devices Processing Devices
Output Devices Storage Devices
QUESTION NO.02:-Explain the term Hardware and Software.
HARDWARE
The physical components of the Computer system are called Computer
hardware. These parts are seen and touched. Monitor, keyboard and Printers
are the examples of the Computer Hardware.
SOFTWARE
A set of instructions grouped into programs that make the Computer to
function in desired ways is called software.
A Computer System becomes useful when both Software and Hardware
are properly combined.
QUESTION NO.03:-Define the following terms Data, Information and Program.
DATA
The collections of facts or figures in raw form that are not used for
decision-making purpose are called data. These raw facts are entered into
GOVERNMENT POSTGRADUATE COLLEGE 2

JHANG
Department of Computer Science

the Computer System as input, processed and transferred into meaningful


information. The word data is plural and its singular is Datum.
INFORMATION
The processed data is known as information. It is meaningful and can be
used for decision making purpose.
PROGRAM
A set of instructions written in some programming language that can be
understood by Computer is called program.
QUESTION NO.04:-Describe the brief history of C-Language.
Brief history
The mastermind behind the inception and development of C++
programming language is Bjarne Stroustrup. He developed C++ at AT&T
Bell Labs, which he was head of till 2002.

Let’s start with a brief history of C as C++ is called the successor of C


programming. C programming language was first introduced by Denis
Ritchie at the AT &T’s Bell Laboratories USA in 1972 and was implemented
for the first time in DEC PDP-11 computer. Denise Ritchie used the concepts
of BCPL and B to develop C and added data typing and some other powerful
features.
The inception of C++ programming language began in 1979
when Bjarne Stroustrup was working in his Ph.D. thesis. During that period
Stroustrup used to work with Simula (regarded as the first language to
support OOP paradigm).
Fascinated by object-oriented approach Stroustrup thought of
implementing this paradigm in software development, however, the Simula
language was far too slow for practical use. So he began working on C with
classes i.e. he started working on a new language which would have object-
oriented paradigm mixed with the features of C programming language.
In 1983, it was named C++ and it included some add-on features such as
classes, inheritance, in-lining, default function arguments, polymorphism,
encapsulation and strong type checking.
The first commercial edition of C++ programming language was released
in October 1985. C++ is the most popular programming language. It is
preferred by many programmers for developing all types of applications such
as Word Processing programs, Spreadsheet Programs, Database
Management Systems and games etc. it is also used to write programs for
controlling many other electronic devices and industrial processes.
GOVERNMENT POSTGRADUATE COLLEGE 3

JHANG
Department of Computer Science

++
QUESTION NO.05:-What is the structure of C -Language program?
STRUCTURE OF C-LANGUAGE PROGRAM
The format or way according to which a computer program is written is
called the structure of C++-Language program. The structure of C++ Program
consists of 3 main parts. These parts are given below.
 Preprocessor Directives. The main( ) function.
 C statements.
++

EXPLANATION
In order to explain the above written three parts, consider the small
program written in C++ language.
Header File
# include<conio.h> Preprocessor
# include<iostream.h> Directives
void main ( ) Main Function
{ Begin
clrscr( );
cout<<" Muhammad Saleem Raza "<<endl;
cout<<"M.Sc. Computer Science "<<endl;
cout<<"University of Agriculture Faisalabad"<<endl; Statements
getch ( );
Statements
} End
Terminator
Escape Sequence used to move cursor to the start of new line.

Q.06:-Write a note on preprocessor Directives?


PREPROCESSOR DIRECTIVES
The commands that give instructions to compiler before the beginning of
++
C program are called Preprocessor Directives. These instructions are also
called Compiler Directives. The Preprocessor Directives consist of
instructions for compiler. These are written at the beginning of the source
code.

Preprocessor Directives normally starts with number/pound/hash sign


(#) and the key word "include" or "define". The program that handles
Preprocessor Directives is called Preprocessor. Preprocessor Directives are
used to include header files in source program. Preprocessor Directives
include specified header files into the source code before compiling.
GOVERNMENT POSTGRADUATE COLLEGE 4

JHANG
Department of Computer Science

Q.07:-What are header files? For what purpose they are used?
HEADER FILES
Header files are the part of C++ compiler and contain the definitions of the
standard library functions. The preprocessor Directive "include" is used to
add header files into the program. The name of the header file is written
between two angle brackets (<>) after "include" Directives. The header file
can also be written in double quotes.

C++ language has number of header files in which Library Functions are
defined. A header file must be included at the start of program before calling
its function in the program. For Example math.h header file contains the
definitions of the mathematical functions available in C++ language. So in
order to use the mathematical formulae in the program, it is necessary to
add this header file in the program. Syntax of including header file in the
program is given:
#include< Header file name> or
#include "Header file name"
Q.08:-Write a note on main ( ) function in the C++ program.
THE main ( ) FUNCTION
The main( ) function indicates the beginning of the program written in
the C++ language. The main( ) function must be included in every C++
program. When a C++ language program is executed, the control directly goes
to the main ( ) function and starts executing the statements written with in
the main( ) function.

The statements within the main( ) function are called body of


program. If main function is not included in the program then program
cannot be compiled and an error message is generated.
SYNTAX
void main(void ) {
Program Statements-------; }
Q.09:-What are C++ statements?
C++ STATEMENTS
The statements of the program are written under the main( ) function of
the program between two curly braces { }. Each statement written in the C
program ends with semicolon (;). This semicolon is called statement
terminator.
GOVERNMENT POSTGRADUATE COLLEGE 5

JHANG
Department of Computer Science

C++ is a case sensitive language. The statements of C program are


normally written in lower case letters but in some cases these can also be
written in the upper case letter.
Q.10:-Distinguish between Source Program and Object Program.
SOURCE PROGRAM
A Computer program written in any high-level language is called source
program. It is also called source code. Computer works only with binary code.
So programs written in high level languages cannot directly run on Computer.
They must be converted into binary code for execution.
OBJECT PROGRAM
A fully compiled program is called object program. It is also called
object code. Since machine language is the native language of Computer, so
a program written in machine language directly runs on the Computer.
Q.11:-What are language preprocessors? Briefly describe their various types.
LANGUAGE PREPROCESSORS
Computer works with Binary code. Programs written in any high level
language are converted into machine language for execution. Special
programs are used to convert the program written in high level language into
object code/ object program. These programs are called language
preprocessors. Every high-level programming language has its own language
preprocessor.

Translators, compilers, interpreters and assemblers are all software


programming tools that convert code into another type of code, but each
term has specific meaning. All of the above work in some way towards getting
a high-level programming language translated into machine code that the
central processing unit (CPU) can understand.
Translators
The most general term for a software code converting tool is
“translator.” A translator, in software programming terms, is a generic term
that could refer to a compiler, assembler, or interpreter; anything that
converts higher level code into another high-level code (e.g., Basic, C++,
Fortran, Java) or lower-level (i.e., a language that the processor can
understand), such as assembly language or machine code. If you don’t know
what the tool actually does other than that it accomplishes some level of code
conversion to a specific target language, then you can safely call it a
translator.
GOVERNMENT POSTGRADUATE COLLEGE 6

JHANG
Department of Computer Science

Compilers
Compilers convert high-level language code to machine (object) code in
one session. Compilers can take a while, because they have to translate high-
level code to lower-level machine language all at once and then save the
executable object code to memory. A compiler creates machine code that
runs on a processor with a specific Instruction Set Architecture (ISA), which
is processor-dependent.
Interpreters
Another way to get code to run on your processor is to use an
interpreter, which is not the same as a compiler. An interpreter translates
code like a compiler but reads the code and immediately executes on that
code, and therefore is initially faster than a compiler. Thus, interpreters are
often used in software development tools as debugging tools, as they can
execute a single in of code at a time. Compilers translate code all at once and
the processor then executes upon the machine language that the compiler
produced. If changes are made to the code after compilation, the changed
code will need to be compiled and added to the compiled code (or perhaps
the entire program will need to be re-compiled.) But an interpreter, although
skipping the step of compilation of the entire program to start, is much
slower to execute than the same program that’s been completely compiled.
Assemblers
An assembler translates a program written in assembly language into
machine language and is effectively a compiler for the assembly language,
but can also be used interactively like an interpreter. Assembly language is a
low-level programming language. Low-level programming languages are less
like human language in that they are more difficult to understand at a glance;
you have to study assembly code carefully in order to follow the intent of
execution and in most cases, assembly code has many more lines of code to
represent the same functions being executed as a higher-level language. An
assembler converts assembly language code into machine code (also known
as object code), an even lower-level language that the processor can directly
understand.
Q.12:-Write a note on different features of C++
Features of C ++

C++ is object oriented programming language and it is a very simple


and easy language, It is the enhanced form of C programming language. this
language have following features and here we discuss some important
features of C++.
GOVERNMENT POSTGRADUATE COLLEGE 7

JHANG
Department of Computer Science

Important Features of C++


• Simple

• Portability

• Powerful

• Rich Library

• Platform Dependent

• Object Oriented

• Case Sensitive

• Compiler Based

• Syntax based language

• Use of Pointers

• Memory Management

• Powerful and Fast

Simple
Every C++ program can be written in simple English language so that it
is very easy to understand and developed by programmer.
Platform dependent
A language is said to be platform dependent whenever the program is
execute in the same operating system where that was developed and
compiled but not run and execute on other operating system. C++ is platform
dependent language.
GOVERNMENT POSTGRADUATE COLLEGE 8

JHANG
Department of Computer Science

Note: .obj file of C++ program is platform dependent.


Portability
It is the concept of carrying the instruction from one system to another
system. In C++ Language .cpp file contain source code, we can edit also this
code. .exe file contain application, only we can execute this file. When we
write and compile any C++ program on window operating system that
program easily run on other window based system.

When we can copy .exe file to any other computer which contain
window operating system then it works properly, because the native code of
application an operating system is same.
Powerful
C++ is a very powerful programming language, it has a wide verity of
data types, functions, control statements, decision making statements, etc.
GOVERNMENT POSTGRADUATE COLLEGE 9

JHANG
Department of Computer Science

Object oriented Programming language


This main advantage of C++ is, it is object-oriented programming
language. It follows concept of oops like polymorphism, inheritance,
encapsulation, abstraction.
Rich Library
Developers have access to lots of in-built functions provided by C++
language. This saves time & makes development fast. Let’s look at some of
the C++ header files & functionalities provided by it. It is most important
features of C++ programming language.
++
• <iostream>: Contains C standard input and output functions
• <iomanip>: Contains stream manipulators that format streams of
data
• <cmath>: Contains math library functions

• <cstdlib>: Contains function for conversions of numbers to text and


vise versa, memory allocation, random numbers and various other
utility functions.
• <ctime>: Contains function for manipulating the time and date

• <fstream>: Contains function for functions that perform input from


files on disk and output to files on disk
++
• <memory>: Contains classes and functions used by the C Standard
++
Library to allocate memory to the C Standard Library containers
++
• <iterator>: Contains classes for accessing data in the C Standard
Library containers
++
• <algorithm>: Contains functions for manipulating data in C
Standard Library containers
Memory Management
C++ supports dynamic memory allocation. You can free the allocated
memory at any time. Not only this C++ also provides dynamic memory
management techniques.
Case sensitive
C++ is a case sensitive programming language. In C++ programming
'break and BREAK' both are different.
If any language treats lower case latter separately and upper case latter
separately than they can be called as case sensitive programming language
[Example c, C++, java, .net are sensitive programming languages.] other wise
it is called as case insensitive programming language [Example HTML, SQL
is case insensitive programming languages].
GOVERNMENT POSTGRADUATE COLLEGE 10

JHANG
Department of Computer Science

Compiler based
C++ is a compiler based programming language that means without
compilation no C++ program can be executed. First, we need compiler to
compile our program and then execute.
Syntax based language
C++ is a strongly tight syntax based programming language. If any
language follow rules and regulation very strictly known as strongly tight
syntax based language. Example C, C++, Java, .net etc. If any language not
follow rules and regulation very strictly known as loosely tight syntax based
language.
Example HTML.
Efficient use of pointers
Pointers is a variable which hold the address of another variable,
pointer directly direct access to memory address of any variable due to this
performance of application is improve. In C++ language also concept of
pointer are available.
Advantage of C++ Programming Language
• Abstract data type defining is very good
++
• C language is efficient having less compiled time.
• It is much suitable for large projects.

• Encapsulation, polymorphism, abstraction are the important properties


of C++ language
• Objects, methods, instance, message passing, inheritance are some
important properties inherited by this language
++
• C Programming is easy to maintain and modify existing code as new
objects with small difference to existing ones.
++
• C Programming is implemented on real life scenario.
• The properties of inheritance make simple the program by complexity.
Do not required to write again.
• Implementation details are hidden from other modules which represent
a clearly defined interface.

Q.13:-Define Debugging. What are the different types of errors in the Computer program?
DEBUGGING
Errors occurring in the program are called Bugs. The process of
detecting and removing errors in the program is called Debugging.
TYPES OF ERROR
There are two types of errors in the Computer Program. These errors
are:
GOVERNMENT POSTGRADUATE COLLEGE 11

JHANG
Department of Computer Science

 Syntax Errors
 Logical Errors
 Run Time Errors
SYNTAX ERRORS
Rules for writing statements in Computer Programming language are
called syntax of the language. Program statements are written strictly
according to these rules. A single mistake in these rules causes an error.
This error is called Syntax Error. Compiler detects these errors. It does not
compile the program that contains syntax errors. These errors are easy to
locate and remove.
LOGICAL ERRORS
Errors occurring in the logic of the Computer Program are called
Logical Errors. Compiler cannot detect these errors. A program with logical
errors runs correctly but it provides wrong results. These errors are most
difficult to locate and remove. To detect the logical errors, all units of the
program are examined separately.
Run-Time Errors:
Errors which occur during program execution(run-time) after
successful compilation are called run-time errors. One of the most common
run-time error is division by zero also known as Division error. These types
of error are hard to find as the compiler doesn’t point to the line at which
the error occurs.

You might also like