Document From :)

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

CHAPTER # 1: CONCEPTS OF COMPUTER PROGRAMMING CLASS: XII

Chapter#1: Concepts of Computer


Programming
PROGRAM: A program is a set of instructions written in a language, which a
computer can understand. It directs the computer how to perform a task.

PROGRAMMER: The person who writes program in a specific language is


called a computer programmer.

PROGRAMMING: The process of writing a program is called computer


programming.

VISUAL PROGRAMMING: Visual programming is a method of creating


programs in which the programmer makes connection between objects by
drawing, pointing, and clicking on diagrams and icons.
Visual programming enables user to think more about the problems solving than
about handling the programming language.

PROGRAMMING LANGUAGE: Programming language is a set of


instructions or symbols that directs the computer hardware to perform a specific
operation. Each computer language has its own rules for using words, symbols,
syntax, and statements.

TYPES OF PROGRAMMING LANGUAGES:


There are three types of computer programming languages:
1. Machine Language
2. Assembly or low level languages
3. High level languages

1. MACHINE LANGUAGE:
Machine language is the programming language in which all programming
instructions are in binary number system form. This language uses two
symbols “0” and “1” to represent the data which are also called binary
digits.

2. ASSEMBLY LANGUAGE OR LOW LEVEL LANGUAGE:


Assembly language or low level language is the next level of programming
language. Assembly language requires language translator program called
Assembler, which is used to convert the instructions written in Assembly
language into machine language.

1
CHAPTER # 1: CONCEPTS OF COMPUTER PROGRAMMING CLASS: XII

3. HIGH LEVEL LANGUAGES:


A high-level language (HLL) is a programming language such
as C, FORTRAN, or Pascal that enables a programmer to write programs
that are more or less independent of a particular type of computer.
Such languages are considered high-level because they are closer to human
languages and far from machine languages. The instructions of high level
languages are called statements.

Most commonly used microcomputer high level programming


languages:

1. FORTRAN (Formula Translation)


2. COBOL (Common Business Oriented Language)
3. BASIC (Business All-Purpose Symbolic Instructions Code)
4. Pascal
5. C-Language

LANGUAGE TRANSLATOR PROGRAMS: Language translators are the


programs that convert computer programming language instructions into
machine language instructions.

TYPES OF LANGUAGE TRANSLATOR PROGRAMS: Three different


types of language translator programs are used to translate computer
programming languages.

1. Compiler
2. Interpreter
3. Assembler

1. COMPILER: A compiler translates the whole program which is written in


high level language into machine language.

2. INTERPRETER: An interpreter translates a program into machine


language, one line at a time and executes each line of the program after it is
translated.

4. ASSEMBLER: Assembler is also a translator program which is used to


convert the program written in assembly language into machine language
codes.

2
CHAPTER # 1: CONCEPTS OF COMPUTER PROGRAMMING CLASS: XII

Compiler Interpreter

1. Compiler translates the whole 1. Interpreter translates the whole


program at a time at once. program line by line.

2. Compiler generates an object 2. Interpreter doesn’t generate an


program during compilation. object program during interpretation.

3. It is faster in speed than interpreter. 3. It is slower in speed than compiler.

4. Compiler doesn’t stop the 4. Interpreter displays an error message


execution of a program, if an error if an error exists in a program.
occurs in the program.

5. Example of compiler based 5. Example of interpreter based


languages are: languages are:

C language, COBOL, Visual Basic, Basic, Logo, etc.


etc…

STEPS OF PROGRAMMING:
There are five main steps in programming project/ process.

1. Defining or analyzing the problem


2. Planning the solution or Block Diagram
3. Coding the program
4. Debugging or testing the program
5. Documenting or Executing the Program

Main steps in the programming process

3
CHAPTER # 1: CONCEPTS OF COMPUTER PROGRAMMING CLASS: XII

1. Defining or analyzing the problem:


Problem defining is the first and the most important step in the
programming. A well-defined problem is half solved. The programmer can
determine the problem by talking with the people who works in an organization,
learning about the facilities and the current way of working.

2. Planning the solution:


The second step of programming is using structured programming
techniques or program design tools. These techniques are:
i. Top – down programming
ii. Algorithm
iii. Flowcharts

i. Top Down Program Design:


Once we have determined the outputs and inputs, we can use top-down
program design to identify the program’s processing steps. Such steps are
called program modules.

ii. Algorithm:
Algorithm is a step by step method of designing a program using human
language. It describes the logic and processing of flow of a program.
iii. Flowchart:
Flowchart is a pictorial/ graphical representation of an algorithm of a
program.
3. Coding the program:
Once an algorithm has been developed and its flowchart has been
completed, the next step is to code the program. Coding is the process of writing
instructions in a programming language.

4
CHAPTER # 1: CONCEPTS OF COMPUTER PROGRAMMING CLASS: XII

4. Debugging or Testing the Program:


After the program has been coded, comes the stage to check the program
works or not. Programming errors are known as bugs and the process of detecting
and correcting these errors is called debugging.
Testing is process of making sure whether, the running program is meeting
all the requirements which we have described at first, or not and then eliminate
the program errors.

5. Documenting the Program:


Documentation is a written detailed description of the programming cycle
and specific facts about the program. Documentation is important for different
kind of people like user operators, and programmers who may be involve with
the program in the future.

ERRORS
Bugs: Programming errors are known as bugs.
Debugging: The process of detecting and correcting these errors is called
debugging.
OR
Debugging is the process of locating and eliminating program errors.

TYPES OF ERROR:
1. Syntax Error
2. Logical Error
3. Runtime Error

1. Syntax Error:
The syntax of a programming language is a set of rules which have to be
followed by programmer when writing a program in that language. These rules
are similar to grammatical rules of English. When a program violates these errors,
computer generates a syntax error.
For example, when you are writing the output function in C- language, you cannot
write “print” instead of “printf”.

2. Logical Error:
A logical error will not stop the execution of a program, but result will not
be accurate.
For example, if a programmer wants to multiply A to B and put the result in the
variable C.
C = A*B
But while typing programmer just typed C = A/B, then the result will give the
division instead of multiplication

5
CHAPTER # 1: CONCEPTS OF COMPUTER PROGRAMMING CLASS: XII

Such program will run properly but it will give the unexpected result.

3. Run-time Errors:
Run-time error occurs when a program is running on the computer and
results are not achieved due to misinterpretation of a particular instruction. This
could be something like dividing a number by zero which results in a very large
value of quotient.

Syntax Error Logical Error

1. Syntax errors are caused by typing 1. Logical errors are caused by


mistake, spelling mistake, missing or mistakes that have been in the logical
extra comma. organization of the program.

2. Syntax errors are shown on screen. 2. Logical errors are not shown on
screen.

3. Syntax errors stop the execution of 3. Logical errors do not stop the
a program. execution of a program.

Source Program Object Program

1. A program which is written in any 1. A source program which is


computer language is called a source converted into machine language is
program. called an object program.

2. Source program is always in high 2. Object program is always in


level language. machine language.

3. Computer cannot execute source 3. Computer can execute object


program directly. program directly.

4. Source program cannot be read 4. Object program can be read directly.


directly

6
CHAPTER # 1: CONCEPTS OF COMPUTER PROGRAMMING CLASS: XII

Questions
1. Define the term Program, Programmer, Programming and Visual
Programming? (Short)

2. What is a Programming language? How many types of programming


languages? Name them. (Short)
3. Define High-level languages. Write the most commonly used
microcomputer high level programming languages. (Short)
4. What is a Programming language? How many types of programming
languages? Name/define them. (Long)
5. Define language Translators. Write the name of types of language
translators. (Short)
6. Define Language Translators? Define the different types of language
translators. (Long)
7. Write the difference between a compiler and an interpreter. (Short)
8. Write the five main steps of programming process and draw the diagram
of steps in programming-process. (Short)
9. Explain all the steps of programming process. (Long)
10.Define the term Bug and Debugging. Also write the types of error/bug.
(Short)
11.Write difference between syntax and Logical Error. (Short)
12.Write difference between source and object program. (Short)
13.What are the bugs? How many types of error in computer programming?
Explain them with example. (Long)

7
CHAPTER # 1: CONCEPTS OF COMPUTER PROGRAMMING CLASS: XII

MCQ’s (Multiple Choice Questions)


1. In preparing a program, one should first
(a) plan the solution (b) document the program
(c) code the program (d) define the problem
2. During the development of a program, drawing a flowchart is a means
to:
(a) plan the solution (b) define the problem
(c) code the program (d) analyze the problem
3. Which of the following is used to design a program using English-like
statements?
(a) Algorithm (b) program flowchart
(c) control structures (d) None of the above
4. Compiler and interpreters are types of
(a) programming languages (b) language translators
(c) alpha testers (d) application generators
5. Which of the following type of error is detected by a language
translator?
(a) program design (b) logic
(c) syntax (d) both b and c
6. You test a program to find which of the following?
(a) flowcharting errors (b) logic errors
(c) algorithm errors (d) syntax errors
7. In preparing a program, desk-checking and translating are examples
of:
(a) coding (b) testing (c) planning (d)
documenting
8. Which of the following is not one of the steps in a programming
project?
(a) planning the solution (b) coding the program
(c) testing the program (d) selecting the hardware
9. Comments in the program itself are part of:
(a) compiling (b) translating (c) linking (d)
documenting
10. The language named for a French mathematician is
(a) COBOL (b) C (c) PASCAL (d) FORTRAN
11. Error messages provided by a compiler are called
(a) bugs (b) translating (c) diagnostics (d) mistakes
12. In developing a program, documentation should be done
(a) as the last step (b) only to explain errors
(c) throughout the process (d) only during the design phase

8
CHAPTER # 1: CONCEPTS OF COMPUTER PROGRAMMING CLASS: XII

13. Computer cannot detect this error


(a) Runtime (b) Logical (c) Absolute (d) Syntax
14. A program that is written in high level language and is converted to
low level language is known as:
(a) op-code (b) source code (c) object code (d) none of these

9
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Chapter#2: Algorithm and Flowcharts


ALGORITHM: Algorithm is a step by step method of designing a program
using normal human-language statements. It describes the logic, processing, and
flow of a program. It is like an outline or summary form of the program we will
write.

Example1:
Write an algorithm to compute the distance travelled by train in the
specific time.
Step1: Start the program.
Step2: Read value for SPEED.
Step3: Read value for TIME.
Step4: Set DISTANCE = SPEED * TIME
Step5: Write value of DISTANCE.
Step6: Exit.

Example2:
Write an algorithm to prepare the students’ mark sheet.
Step1: Start.
Step2: Read marks of all subjects.
Step3: Sum all subject’s marks as, Set TOTAL = ENG + MATH+ URDU +
PHY + ISL +COMP
Step4: Calculate percentage as, Set PERCENTAGE =
TOTAL*100/MAX_MARKS
Step5: Write marks of all subjects.
Step6: Write MAX_MARKS, TOTAL, and PERCENTAGE.
Step7: Exit.

PSEUDOCODE:
The prefix pseudo means fake; pseudo-code, therefore literally means fake
code- that is, not the code actually it is entered into the computer. It is considered
as the “First Draft”. In this we can concentrate on the logic of a specific language.

ALGORITHM NOTATION
OR
CERTAIN POINTS AND TERMINOLOGIES USED IN MAKING
ALGORTHM

1. Algorithm Name: Each algorithm must be given a unique name for


identification.
2. Step Number: Each statement of the algorithm must be given a unique
number for identification.

1
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

3. Variable Names: Variable names will use capital letters, as X, Y, SUM,


NUM, etc.
4. Getting Input from the user: “Read” word is used to get input from the
user.
5. Assigning value to a variable: “Set” is used to assign a value to a
variable.
6. Algorithm Termination: “Exit” is used to terminate the algorithm.
7. Comments: “[“ and “]” are used for providing comments or remarks.
8. Displaying Output on the screen: “Write” word is used to display
output on the screen
9. Control Transfer: Use “Got to Step n” to transfer control to step n.

Example:

Write algorithm that takes two numbers and generates output of their
sum:
Step1: Start
Step2: Read X [to get first number]
Step3: Read Y [to get second number]
Step4: Set SUM = X + Y [Adding two numbers]
Step5: Write SUM [displaying sum of two numbers]
Step6: Exit [Terminate of program]

FLOWCHART: A flowchart is a graphical or pictorial representation of any


algorithm which is used in a program.
The flowchart uses arrows to represent the direction of the program flow and
boxes and other shapes to display.
Symbols and Boxes:The American National Standard Institute (ANSI) has
established standard for symbols and boxes that are used in flowcharting. The
shape of the boxes represents the type of activity that is to be performed.
List of the symbols of flowchart:The pictorial symbols that used flowcharts
are defined below:
1. Terminal Symbol
2. Arrow or Flow lines
3. Input/ Output Symbol
4. Process Symbol
5. Decision Symbol
6. On-page Connector Symbol
7. Off-page Connector Symbol
8. Predefined Process Symbol
9. Printed Document Symbol
10. Annotation Symbol

2
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

1. TERMINAL SYBOL:
The terminal symbol is used to indicate the beginning (start), ending (Stop) and
pauses (Halt) in the program’s logic flow.
Oval
Halt Start Stop

2. ARROWS / FLOW LINES:


In flowchart, flowchart symbols are connected to each other with lines called
“flow lines”. These arrows represent the direction of program flow.

3. INPUT/ OUTPUT SYMBOLS:


This symbol is used to denote any type of input data or output information.

Read X Write X
Parallelogram

4. PROCESS SYMBOL:
The process box indicates processing operations in the form of variables and
formulas.
OR
The process box is used for all arithmetic and data transfer operation

Rectangle

5. DECISION SYMBOL:
It is used whenever a decision of a condition is required in the form of yes or
no, true or false, less than or greater than, equal to or not equal to.

If Yes
A=10

No
Diamond

3
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

6. ON-PAGE CONNECTOR SYMBOL:


It is used to branch/ connect flow of program on the same page. An on-page
connector symbol is represented by a circle and a letter or digit is placed within
the circle to indicate the link.

A
Circle

7. OFF – PAGE CONNECTOR SYMBOL:


It is used to connect flow of program from one page to another.

A
Pentagon

8. PREDEFINED PROCESS SYMBOL:


Predefined process symbol indicates the number of processing steps, a sub-
program or sub-routine.

For
A=1 to 10
[FOR,
WHILE,
DO WHILE]
9. PRINTED DOCUMENT SYMBOL:

This symbol indicates printed output of data on paper as hard copy output.

10. ANNOTATION SYMBOL:


This symbol holds additional descriptive, comments, explanatory notes, or
clarifications; connected by dashed line to the symbol. It is used as needed to
aid understanding.

4
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

ADVANTAGES OF FLOWCHART:
 Communication: Flowcharts are better way of communicating the logic of
a system to all concerned or involved.
 Effective analysis: With the help of flowchart, problem can be analyzed in
more effective way therefore reducing cost and wastage of time.
 Proper documentation: Program flowcharts serve as a good program
documentation, which is needed for various purposes, making things more
efficient.
 Efficient Coding: The flowcharts act as a guide or blueprint during the
systems analysis and program development phase.
 Proper Debugging: The flowchart helps in debugging process.
 Efficient Program Maintenance: The maintenance of operating program
becomes easy with the help of flowchart. It helps the programmer to put
efforts more efficiently on that part.

DISADVANTAGES OF FLOWCHART:
•Complex logic: Sometimes, the program logic is quite complicated. In that
case, flowchart becomes complex and clumsy. This will become a pain for the
user, resulting in a waste of time and money trying to correct the problem
•Alterations and Modifications: If alterations are required the flowchart may
require re-drawing completely. This will usually waste valuable time.
•Reproduction: As the flowchart symbols cannot be typed, reproduction of
flowchart becomes a problem.

RULES AND GUIDELINES:


 Keep flowchart as simple as possible.
 Do not include many details; they will appear in the program.
 Words in the flowchart symbols should be common statements and easy
to understand.
 Be consistent in using names and variables in the flowchart.
 Each symbol of a flowchart should probably be connected with each
other by arrows.
 Go from left to right and top to bottom in constructing a flowchart.
 Each connector should have an alphabet or a number in it.
 There must be a statement inside every symbol accordingly.
If more than one flow lines are required to enter in any symbol, then they should
be connected by flow line to flow line.

5
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

CONTROL STRUCTURES
Control Structures control how the program executes.
Three types of control structures:
1. Sequence Logic or Sequential Flow
2. Selection Logic or Conditional Flow
3. Iteration Logic or Repetitive Flow

1. SEQUENCE LOGIC OR SEQUENTIAL FLOW:


It is the straightest forward. One module simply follows another in
sequence.
Example of Algorithm:
Step1: Start
Step2: Read NUM1, NUM2
Step3: Set SUM=NUM1+NUM2
Step4: Write SUM
Step5: Exit
Example of Flowchart:

2. SELECTION LOGIC OR CONDITIONAL FLOW: The selection control


structure set a number of conditions, which lead to a selection one out of several
alternative modules. These structures are called conditional or IF structures.

Examples of IF and IF-ELSE by Flowchart:

6
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

General Flowchart for IF Structure General Flowchart for IF ELSE Structure

3. ITERATION LOGIC OR REPETITIVE FLOW


Iteration is often referred to as loops because the program will keep
repeating the activity until the condition becomes false.
There are three iteration logics:
1. FOR
2. WHILE
3. DO – WHILE

7
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

FOR:
The FOR loop uses an index variable, such as “K” to control the loop.

FOR K =1 to 10
Example of FOR loop:

2. WHILE LOOP…..

While- loop tests condition at the beginning of the loop.

8
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

3. DO – WHILE LOOP….
The Do-WHILE loop tests condition after execution of at least once of
loop.

9
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

SOME EXAMPLES OF ALGORITHM AND FLOWCHART

Example 1: Write an algorithm which reads and write your name, age,
height, and gender.

ALGORITHM:

Step1: Start

Step2: Read GENDER, NAME, HEIGHT, and AGE.

Step6: Write GENDER, NAME, HEIGHT, and AGE

Step7: Exit

FLOWCHART:

10
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Example 2: Write an algorithm for printing your name ten times using FOR
Statement.

ALGORITHM:

Step1: Start
Step2: FOR A=1 to 10
a) Write “Name”
b) A = A+1 [END OF FOR LOOP]
Step3: Exit

FLOWCHART:

11
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Example 3: Write an algorithm and draw a flowchart to calculate square


and cube of first natural numbers.

ALGORITHM:

Step1: Start
Step2: FOR A = 1 to 10 by 1
a) Write A, A^2, A^3
b) Set A = A + 1 [END OF FOR LOOP]
Step3: Exit.

FLOWCHART:

12
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Example 4: Write an algorithm and draw a flowchart to generate a table of


inputted number.

ALGORITHM:

Step1: Start
Step2: Read NUM
Step3: FOR A = 1 to 10 by 1
a) Write NUM; “*” A; “=” NUM*A
b) Set A = A + 1 [END OF FOR LOOP]
Step4: Exit

FLOWCHART:

13
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

Questions
1. Define the term Algorithm with the help of examples. (Short)
2. Define the term Pseudocode. (Short)
3. What is an Algorithm? Write the names of Algorithm Notations. (Short)
4. Define algorithm and also define all the algorithm notations. (Long)
5. Define Flowchart. List all the symbols of a flowchart. (Short)
6. What is a Flowchart? List and also describe all the symbols of Flowchart.
(Long)
7. Describe all the Categories of flowchart. (Long)
8. Write the advantages and disadvantages of a flowchart (Short)
9. Describe the rules and guidelines while designing the flowchart. (Short)
10.What are the control structures? And name the types control structures.
(Short)
11.Describe the control structures with the examples of Algorithm and
Flowchart. (Long)

14
CHAPTER # 2: ALGORITHM AND FLOWCHART CLASS: XII

MCQ’s (Multiple Choice Questions)


1. A pictorial representation of a problem is called
(a) a flowchart (b) an algorithm
(c) a pseudo code (d) None of the above
2. What do you call the step-by-step solution to a programming
problem?
(a) recipe (b) structure chart
(c) syntax (d) algorithm
3. What does the symbol in a flowchart represent?
(a) decision (b) process
(c) start/ stop (d) predefined process
4. What does the symbol in a flowchart represent?
(a) process (b) terminal
(c) input/output procedure (d) predefined process
5. Which of the following control structures use DO-WHILE?
(a) sequence (b) selection
(c) iteration (d) None of the above
6. In flowchart, this symbol represents start or finish of program:
(a) Diamond (b) Oval
(c) Rectangle (d) Square
7. The ____________ symbol in a flowchart represents process.
(a) decision (b) process
(c) start/ stop (d) predefined process
8. At least ______ arrows leave the diamond in a flowchart.
(a) one (b) two
(c) three (d) none of them
9. _______ word is used to get input from the user.
(a) Write (b) Read
(c) Scan (d) both b and c
10. In a flowchart, symbols are connected with
(a) arrows (b) flow lines
(c) decision box (d) both a and b

15
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

Chapter#3: An overview of C-Language


INTRODUCTION OF C-LANGUAGE: C is a powerful programming language
developed by “Dennis Ritchie” at Bell Laboratories of USA in 1972. C evolved
from two earlier languages, BCPL (Basic Combined Programming Language) and
B.

 BCPL was developed in 1964 by “Martin Richard” at the Cambridge University


as a language for writing Operating System’s software and Compiler.
 In 1970 “Ken Thompson at Bell Laboratories developed a language based on
BCPL and called it B, the first letter of BCPL.
 “Dennis Ritchie” developed B further into a new language and gave it the name
C, the next letter of BCPL.
 C is developer of the UNIX Operating System. It is also becoming a common
application software programming language.
 C is hardware independent and compiler based language.

ADVANTAGES OF C – LANGUAGE:
1. C has many Advantages over other programming languages.
2. It is an efficient language, suitable for applications that run on PCs or
microcomputer, minicomputers, workstations, and other small machine.
3. It has large variety of operators and commands can be used.
4. It is capable of handling a wide variety of system applications.
5. C is a high level programming language because C uses English like
statements, which is easy to read and east to understand.
6. C enables programmers to have extensive control over computer hardware.
7. C is a portable language. A C-program which is written in one computer can be
run on any computer with little or no modification.
8. It has high execution speed.
9. C is the standard programming language in many industries and applications.
10.It is flexible, by creating your own functions and modules.
SOURCE CODE
The files we create with an editor are called “source file” and what we store
in this file in called “Source Code”. Your Source file is saved with an extension,
“.CPP”.

COMPILING THE SOURE CODE:


Your source code file is not a program, and it cannot be executed, or run as a
program.

1
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

 To turn your source code into a program, you compile it.


 After your source code is compiled, and “object file” is produced with the
extension “.OBJ” (This is still not an executable program; however, to turn this
into an executable program you must run your linker.
 C programs are typically created by linking together one or more OBJ files with
one or more libraries.

LIBRARY: A library is a collection of linkable files that are supplied with compiler.
Turbo C++ Compiler comes with a library of useful functions and classes that you
can include in your program.

FUNCTION: A function is a block of code that performs a service.

STEPS TO CREATE AN EXECUTABLE


Steps to create an executable file are:
1. Create a source code file with a “.CPP” extension
2. Compile the source code into a file with the “.OBJ” extension.
3. Link your OBJ file with any needed libraries to produce an executable program
with the “.EXE” extension.
4.

Note: Executable codes have software library, which tells the meaning of
instruction’s words.

Turbo C++ is an IDE (Integrated Development Environment) and compiler


for the C programming language from Borland. First introduced in 1987, it was
noted for its integrated development environment, small size, fast compile speed,
comprehensive manuals and low price.

2
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

IDE: An Integrated Development Environment or IDE is a software application


that provides comprehensive facilities to computer programmers for software
development. An IDE normally consists of at least a source code editor, build
automation tools, and a debugger.

File Name
Menu Bar
Window Number

Click on this to Edit Window


close window
Vertical Scroll
Horizontal Scroll

Quick Reference Message Window


Keys

RULES AN REGULATION OF TURBO-C++:

 Must be lower case; abc ABC


(It is case sensitive language)
 Must be “ ; ” at end of each statement
 Must be balanced braces { }
 Must be “main( )” method or function.
 File extension “.CPP”

BASIC STRUCTURE OF C – LANGUAGE


#include<stdio.h>
Header files Example:
#inclue<conio.h> #include<stdio.h>
Function Name
void main(void) #include<conio.h>
Start of Function void main(void)
{
{
statement1… Body of a function printf(“This is my first C Program”);
statement2… }
} End of function

#include<stdio.h>:

3
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

 ‘#’ are called preprocessing directives. This # include directives tells the
compiler to use the information in the header file called “stdio.h”
 The ‘stdio’ stands for “standard input/ output” and ‘h’ stands for header file.
 The “stdio.h” file contains all the instructions and sends information to the
screen.
 The angle brackets ‘<>’ around the <stdio.h> indicate that this file to be found
in the “usual place” which is system dependent.
 Another header file is <conio.h> in which ‘conio’ stands for “console input/
output.

void main(void):
 C programs are collection of “functions” designed to perform a specific task
and return a computed result.
 All C programs must specify a function “main”.
 ‘( )’ parenthesis of main indicate the compiler that it is function.
 The ‘void’ before ‘main’ specifies that the function main( ) will not return a
value.
 The ‘void’ in the parenthesis, specifies that the function takes no arguments.

{ }:
 This bracket called “Braces”
 The left brace begins the body of function.
 The right brace must end the function.

printf():
 This is function from the library.
 It is used to print on the screen.
 It is accessible through the standard input/output (stdio.h) header file.
“string”:
 A string constant in C language is a series of characters marked by the
quotation marks.
“This is my first C program”
 This string is an “argument” to the function printf( ), which controls what is to
be printed.
printf(“ ”)

4
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

 Every statement must end with “ ; ” (semicolon) which is also known as


“statement terminator”
 We can put several statements on a line.

SAVE FILE:

 After you have entered source code.



 Pull down the file menu (or Alt+F) and press S to save file.

 Type the name of your program when the dialogue box appears.

 The default Turbo C’s name “NONAME00.CPP”

 You don’t have to type “CPP” extension, Turbo C++ automatically assign .CPP
extension.

 After enter the file name, suppose FIRST PROGRAM and press enter, the file
name, FIRST PROGRAM. CPP appears in the caption bar instead of
NONAME00.CPP.

UNDERSTANDING ARGUMENTS:
When we use a function in a statement, such as printf( ), we are to be “calling
the function”
Argument: An argument is an item of information that needs in order to complete
its tasks (arguments are also referred to as parameters).
For Example: printf( ) is a function in the library. The function contains instructions
that tell the computer to print a string of characters on the screen. But what string
does it display? You have to tell it, by placing what you want to display, in
parentheses.

COMMENTS:
 A comment is a message to anyone reading the program.
 Adding comments makes your program easier to understand.
 Comments can appear in everywhere in a program.
 They are ignored by compiler or linker.
 They are never added to the object code or to the executable program.

5
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

There are two types of comments in C-Language:


1. One Line (Single Line)  //
2. More than one line (Multi Line)  /* */

SINGLE LINE COMMENT “//”:

 This type of comment use when a programmer want to write a remark in a


single line
 If the comments run over one line, however each line must start with ‘ // ’
Example: //This program displays a word on the monitor
#include<stdio.h>
void main(void) //starts of a main function
{
printf(“Hello” ); //The function prints a word Hello
}

MULTI-LINE COMMENT “/* */”:


 /* indicates the start of the comment and */ indicates the end of the comment.
 If we have lengthy comments (more than one lines), type as many lines as you
want between the codes.

Example:
/* this program display a word Hello on the monitor screen and includes a void
main(void) function to make it compatible with Turbo C++ Compiler that required
it. */

****Comments within a program explain a particular instruction or point or


logic***

ESCAPE SEQUENCES:
 To control the way the cursor moves on your monitor screen, and some other
compiler functions, by using special codes, called “Escape Sequence”.
 An escape sequence starts with backslash ‘\’
 After the back slash ‘\’ use a single character. So that the character is having a
special meaning.

Escape
Description
Sequence

6
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

\n Inserts a newline in the text at this point.

\t Inserts a tab in the text at this point.

\r Inserts a carriage return in the text at this point.

\b Inserts a backspace in the text at this point.

\f Inserts a form feed in the text at this point.

Inserts a single quote character in the text at this


\’
point.

Inserts a double quote character in the text at this


\”
point.

Inserts a backslash character in the text at this


\\
point.

“\n”:

 The escape sequence ‘\n’ performs a new line.


 It can appear anywhere inside the double quotes and moves the cursor to start
of the next line.
Example:
printf(“This is\n my first\n C program”);
This will generate the display of three lines like:

This is
my first
C program

“\t”:
 The escape sequence ‘\t’ tab moves the cursor to the next present tab stop.
(tab = 9 spaces)
Example:
printf(“This is\n\t my first\n\t\t C program”);
This will generate the output like:

This is

7
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

my first
C program

“\r”:
 The escape sequence ‘\r’ tab performs a carriage return, moving the cursor to
the start of the line.Example:
printf(“Left\rRight”);
This will generate the output like:

Right

The screen displays only the word Right. Here is why: After displaying the left, the
\r code moves the cursor back to the start of the line. The word Right is displayed,
replacing the characters of the word Left.

RULES OF GOOD PROGRAMMING PRACTICE:


 Every program must have void main(void) function with opening and closing
braces.
 Every program or function should be preceded by a comment describing the
purpose of the program or function.
 C language is a case sensitive language. Commands and functions name are
always written in lowercase characters, so we use printf( ) rather than PRINTF(
) or Printf( ).
 Uppercase is reserved for constants and symbolic names.
 End of each statement, put “ ; ”semicolon.

8
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

Questions:
1. Give the Introduction of C-Language. (Short)
2. Write the advantages of C-Language. (Short)
3. Define the term Source Code. And also write the steps to compile the source
code. (Short)
4. Define the term Library and Function in C-Language. (Short)
5. Write the steps to create an executable file. (Short)
6. What is an IDE? What platform we use to write programs in C-Language?
Describe with the help of diagram. (Long)
7. Write the rules and regulations which a programmer has to follow while
writing a program. (Short)
8. Write the Basic Structure of C-Language Program. (Short)
9. Describe all the elements of the Basic structure of C-Language Program.
(Long)
10.What do mean by arguments in C language? Explain your concept by giving
an example of it. (Short)
11.Write the steps to save the file of C-Language source code. (Short)
12.What are the Comments in C and How many types of Comments? Name them.
(Short)
13.Explain the types of comments with the help of example. (Long)
14.What are the Escape Sequences? Name some escape sequences. (Short)

15.What are the Escape Sequences? Explain some of them. (Long)

16.Write some rules of Good Programming Practice. (Short)

9
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

MCQ’s (Multiple Choice Questions)


1. C-language is developed by:
(a) Dennis Ritchie (b) Eric Richard
(c) Charles Babbage (d) Blaise Pascal
2. Every C program must have this function:
(a) scanf( ) (b) main( ) (c) printf( ) (d) none of these
3. This sub directory contains header files:
(a) lib (b) include (c) bin (d) bgi
4. Every C statement must be terminated with:
(a) , (b) ” (c) ; (d) ’’
5. The full form of IDE is:
(a) Integrated Design Environment
(b) Integrated Development Environment
(c) Internal Design Environment
(d) Interconnected Development Environment
6. The library routines are attached to object program through:
(a) Compiler (b) Linker (c) Assembler (d) Interpreter
7. Shortcut key for only compiling a program is:
(a) Ctrl + F9 (b) Alt + F9 (c) F7 (d) Ctrl + F3
8. After compilation, the extension of a program file is:
(a) .ccp (b) .cp (c) .obj (d) .exe
9. A comment is a message to:
(a) anyone reading the program (b) to compiler
(c) to linker (d) to Assembler
10. The escape sequence \t is used to:
(a) Producing beep (b) Carriage return
(c) Moving the cursor to the next tab stop
(d) New Line
11. This one of the following represents comment in C:
(a) <> (b) [ ] (c) /* /* (d) /* */
12. Shortcut key to run a program is:
(a) Ctrl + F9 (b) Alt + F9 (c) F7 (d) Ctrl + F3
13. Shortcut key to save a program is:
(a) F2 (b) F4 (c) F7 (d) Ctrl + F3

10
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

Q1. State the errors in the following programs and rewrite them.

(i) #include<stdio,h> Write . before h instead of , in stdio.h


void main(void)
( Use Curly Brace instead of Round bracket
printf(‘I am a college student’) Double quotes (“) and terminator is missing
}

Rewrite:
#include<stdio.h>
void main(void)
{
printf(“I am a college student”);
}

(ii) void main viod Missing ( ), spelling mistake ‘viod’


( Write Curly brace instead of Round bracket
printf(‘I am a good programmer’); missing double quotes (“) in a statement
) Put Closing curly brace

Rewrite:

void main(void)
{
Printf(“I am a good programmer”);
}

11
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

Q2. Write the output of the following program:


(i) void main(void)
{
printf(“hello world”);
printf(“\n\tthis is my first c language program”);
}

Output:
hello world
this is my first c language program

(ii) void main(void)


{
printf(“name:\talex”);
printf(“\naddress:\tsindh, karachi”);
printf(“\nphone:\t+923334209211”);
}

Output:

Name: alex
address: sindh, karachi
phone: +923334209211

12
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

(iii) void main(void)


{
printf(“left\rright”);
printf(“\nhellow\rworld”);
}

Output:
right
worldw

(iv) void main(void)


{
printf(“This is \n”);
printf(“my first\n”);
printf(“C Program”);
}

Output:
This is
my first
C Program

(v) void main(void)


{
printf(“This is\n\tmy first\n\t\tC Program”);
}

Output:
This is
my first
C Program

13
CHAPTER # 3: AN OVERVIEW OF C-LANGUAGE CLASS: XII

Q3. Write a program to displays the following on the screen:


(i) Welcome to the Computer Lab
Board of Intermediate Education Karachi

Source code:
void main(void)
{
printf(“Welcome to the Computer Lab”);
printf(“\nBoard of Intermediate Education Karachi”);
}

(ii) “I Love my Pakistan”

Source Code:

void main(void)
{
printf(“\“I Love my Pakistan\””);
}

(iii) To Continue, press:


‘ENTER’ key

Source Code:

void main(void)
{
printf(“To Continue,\tpress:\n\‘ENTER\’ key”);
}

14
CHAPTER # 4: C FUNDAMENTALS CLASS XII

Chapter#4: C Fundamentals
DATA:
We refer to input given to the computer as data. You feed data into the computer,
the computer processes it following your instructions and give you information as output.
Before you input data your program, you have to tell it what type of data program is dealing
with.

THE C CHARACTER:
A character denotes any alphabet, digit or special symbol used to represent
information. The valid alphabets, numbers, and special characters allowed in C are listed
below:
Alphabets A, B, C, …, Z
a, b, c,…., z
Digits 0, 1, 2, …, 9
Special Characters = - * / = % & # @ $ ! ? ^ ~ “ ‘ \ | <> ( ) { } ; : , _ blank
space

IDENTIFIERS AND KEYWORDS


IDENTIFIERS:
Identifiers are the name which we give to the various program elements, such as
variables, functions, and arrays.
Rules must be observed while constructing identifiers:
- An identifier must start with a letter or an underscore ( _ ).
- An identifier can contain letters, digits, or underscore.
- An identifier cannot contain blanks, commas, or any other special characters.
- An identifier cannot consist of more than 31 special characters.
- An identifier must conform to case sensitivity. For example, the identifier MAX is
not the same as the identifier max.

Valid Identifiers:
x y1 y2 Sum_1 Sum2 TABLE table
tax_rate _auto _temperature

Invalid identifiers with their reasons:

triangle area illegal character (blank space)


tax-rate illegal character (-)
“x” illegal characters (“)
east#west illegal character (#)
5th the first character must be a letter or underscore
– temperature do not mistake – for _
1
CHAPTER # 4: C FUNDAMENTALS CLASS XII

RESERVERD WORDS/ KEYWORDS:


There are certain reserved words, called keywords, that have standard, predefined
meanings in C. these keywords can be used only for their intended purpose; they cannot be
used as variable names.
The standard keywords for Turbo C++ are:
auto continue far interrupt signed unsigned
asm default float sizeof void break
for do near static volatile case
double goto pascal struct cdecl else
huge register switch char if return
const include int short union long

DATA TYPES:
The data items are classified into data type to prevent data values from being
manipulated with the wrong operations and to prevent their representations being
misinterpreted.
C supports several different types of data, each of which may be represented differently
within the computer’s memory. The basic data types, their description, and the memory
requirements for each data type is listed in the following table:
DATA MEMORY
DESCRIPTION
TYPES REQUIREMENT

Int Integer quantity 2 bytes


char Single character 1 byte
Floating point number (i.e., a number
float containing a decimal point and/ or an 4 bytes
exponent
Double-precision floating point number (i.e.
double more significant figures which may be larger 8 bytes
in magnitude)

1. int Data Type:


The int data type represents integer values, meaning any positive or negative numbers,
or zero, without a decimal point. When such values appear in the program, they are
called integer.
Examples of valid integers are:
4 -87 +9345 -18239

2
CHAPTER # 4: C FUNDAMENTALS CLASS XII

An integer consists of an optional plus or minus sign followed by a series of digits and
cannot contain any other character. Commas, decimal points, or special symbols such as $
or e for exponential notations are not allowed.

BYTES
DATA TYPES RANGE FORMAT
WIDTH

short signed int -32768 to +32767 2 %d

short unsigned
0 to 65535 2 %u
int

-2147483648 to
long signed int 4 %ld
+2147483647

long unsigned
0 to 4294967295 4 %lu
int

2. float Data Type:


The float data type represents floating-point values, meaning any signed or unsigned
number having a decimal point. Examples of valid float variables are:
2. -78.294 395.20587 +95.0 -439
A float consists of an optional plus or minus sign followed by a series of digits and must
include a decimal point. It cannot contain commas or special characters such as dollar sign
but it can include e. float can be single or double (double-precision, which occupy twice
the number of bytes as float).
float and double can be written in scientific notation if needed. For Example:

2.73e + 3

Mantissa Characteristic
Base 10 —power to
Sign indicates
which base is
direction in
which point 10 is raised
is shifted

3
CHAPTER # 4: C FUNDAMENTALS CLASS XII

The number is written as a value (the mantissa), which is multiplied by 10 (represented


by letter e or (E) which stands for ‘Exponent’) to the stated power (the characteristics).
Below are some numbers in exponential notation along their equivalents in floating point
notation:

Exponential Notation Float Notation

7.262e+4 72620.0

-2.1613e+2 -216.13

3.14E–3 0.00314

-729.0e–2 -7.29

The long double may refer to a separate “extra-large” double-precision data type. It stores
an 80-bit floating point number.

BYTES
DATA TYPES RANGE FORMAT
WIDTH
float 3.4e–38 to 3.4e+38 4 %f

double 1.7e–308 to 1.7e+308 8 %lf

long double 3.4e–4932 to 1.1e+4932 10 %Lf

3. char Data Type:


A char represents individual characters. Hence the char type requires only one byte of
memory. A char is any valid ASCII (American Standard Code for Information
Interchange) character enclosed in single quotes.

‘m’ ‘>’ ‘H’ ‘2’ ‘{’ ‘!’ ‘F’

BYTES
DATA TYPES RANGE FORMAT
WIDTH

signed char -128 to 127 1 %c

unsigned char 0 to 255 1 %c

4
CHAPTER # 4: C FUNDAMENTALS CLASS XII

CONSTANTS

CONSTANTS:
Constants are quantities whose values do not change during program execution.
TYPES OF CONSTANTS:
There are four basic types of constants in C.
1. Integer Constants 2. Floating Point Constants
3. Character Constants 4. String Constants

Integer Constants:
An integer constant is an integer-valued number. Thus it consists of a sequence of
digits.
Following rules must be observed while constructing integer constants:
 An integer constant must have at least one digit.
 It must not have a decimal point.
 It could be either positive or negative.
 If no sign precedes an integer constant it is assumed to be positive.
 No commas or no blanks are allowed within an integer constant.
 The allowable range for integer constant is -32768 to +32767.
Integer constants include decimal, octal, and hexadecimal constants.
Decimal Integer Constants: A decimal integer constant can consist of any
combination of digits from 0 to 9. If the decimal integer constant contains two or more
combination of digits, the first digit must not be a 0.
Examples of valid decimal integer constants are:

237 -597 0 3 666

Examples of invalid decimal integer constants are:

08 574-26-28 -36.28 67 29
Octal Integer Constants:
An octal integer constant can consist of any combination of digits from 0 to 7. However,
the first digit must be 0, in order to identify the constants as an octal number.
Examples of valid octal integer constants are:
0 01 -0573 0666
Examples of invalid octal integer constants are:
05927 264
Hexadecimal Integer Constants:

5
CHAPTER # 4: C FUNDAMENTALS CLASS XII

A Hexadecimal integer constant can consist of any combination of digits from 0 to 9


and letters a to f (either lower- or uppercase). Hexadecimal integer constant must begin
with 0x or 0X in order to identify it.
Examples of valid hexadecimal integer constants are:
0x 0x2 -0x275A 0xabcd
Examples of invalid hexadecimal integer constants are:
0XDFG
0x14.9A
9AC5

Floating Point Constants:


Floating point constants are also called real constants. These are base-10 numbers and
could be written in two forms, fractional form and exponential form (or both).
Examples of valid floating-point constants are:
0. 1. -0.5 0.0001 3E-7 3e-7 0.002e+3 .2191129e19

Examples of invalid floating-point constants are:


3 no decimal point or exponent
7,00.0 illegal character (,)
2e+5.6 the exponent value must be an integer
5e 2 illegal character (blank space in the exponent)
2.7e the exponent sign must be followed by a number

Character Constants:
A character constant is a single character, enclosed in apostrophes (i.e.; single quotation
marks). They include the letters of alphabet (lower and uppercase), the numerals 0 to 9,
punctuation marks such as :, ; and ?, and special characters such as &, +, -, #, and $.
Some examples of valid character constants are:
‘B’ ‘m’ ‘5’ ‘*’ ‘?’ ‘ ’
The following character constants are written incorrectly for the reason stated.
‘3 missing right quotation mark
‘73’ more than one character inside quotation marks
# quotation marks missing
Virtually all the PCs make use of the ASCII character set to encode a character. The code
can represent 128 (i.e. 27 = 128) different characters. For example, the ASCII code for ‘A’
is 65.

String Constants:
6
CHAPTER # 4: C FUNDAMENTALS CLASS XII

A sequence of zero or more characters enclosed by double quotes is called a string


constant.
Some examples of valid string constants are:
“My Name is Hugh Packman”
“510909_29892”
“12= Qasim Rd.”
“ ”
Below are two incorrect examples:
“The city (missing right quotation mark)
‘A brown cat’ (must use double quotation marks)
VARIABLES
VARIABLES:
A variable is programmer-defined identifier whose value can change during
execution of the program. All variables must have a name and a data type. C supports most
of the common data types for variables -- integer, float, and character.
Rules for constructing variable names:
 The first character in the variable name must be an alphabet.
 No commas or blanks are allowed within a variable name.
 No special symbol other than an underscore (as tax rate) can be used in a variable
name.
Declaration of Variables:
A declaration associates a group of variables with a specific data type. A declaration
consists of a data type, followed by one or more variable names, ending with a semicolon.

Example of variable names and their data types as they declared at the beginning of the
function look like:
void main(void)
{
int num;
float fl_num;
char ch;
}

If we have several variable names of same data type, separate each variable with comma
and end the declaration with semicolon.
void main(void)
{
int num, count, student, year;
float fl_num, discount;

7
CHAPTER # 4: C FUNDAMENTALS CLASS XII

char ch, answer;


}

We can also declare variables as following:


void main(void)
{
int num;
int count;
int student;
int year;
float fl_num;
float discount;
char ch;
char answer;
}

Variable Initialization:
In computer programming, initialization (or initialization) is the assignment of an initial
value for a data object or variable.
We can assign an initial value either in the declaration or as a separate instruction.

Example of initialization as declaration instruction:


void main(void)
{
int count = 5;
char ch = ‘A’;
float fnum= 3.44;
}
Example of initialization as a separate instruction:
count = 5;
ch = ‘A’;
fnum = 3.44;

ARRAYS:
An array is an identifier that refers to a collection of data items that all have the same name.
C does not contain a string type and it doesn’t have any built-in string functions.
Fortunately, C allows us to work with string type data through the use of arrays.
To declare a string variable, we use the char variable type and specify the maximum
number of characters that the variable can hold.
Syntax:
char varname[n];
varname is name of the variable, and n is the maximum number of characters.

8
CHAPTER # 4: C FUNDAMENTALS CLASS XII

Suppose we need a variable to store a name. Thus we can declare the variable like:
char name [10];

if we want to store a short paragraph as string thus, we need to declare a variable like:

char para [80];

Questions
1. Define the term Data. (Short)
2. Describe the “C-Character” and make some list of characters used by C. (Short)
3. Define the term Identifiers. State and also explain the rules while constructing
identifiers with examples. (Long)
4. Write some Valid and Invalid Identifiers and give reasons for Invalid Identifiers.
(Long)
5. What do you mean by the term reserved words or keywords? State why a keyword
cannot be used as identifier? Write standard keywords used by Turbo C. (Short)
6. What are the data types? How many data types are used by C-Language? Name
them. (Short)
7. Explain all the data types used by C-Language with the help of suitable examples.
(Long)
8. What are the constant? How many types of Constants in C? Name them. (Short)
9. What are the Integer constants? Explain in detail. (Short)
10.What are the Floating point constants? Explain them with examples. (Short)
11.What are the Character constants? Explain them with examples. (Short)
12.What are the String constants? Explain them with examples. (Short)
13.Explain all the Constants in C with the help of examples. (Long)

14.Define the term Variable and write the rules for constructing variable name.
(Short)

15.Describe Declaration of Variables with examples. (Short)

16.Describe Variable Initialization with suitable examples. (Short)

17.Define the term Array. Also write the syntax for Array in C. (Short)

9
CHAPTER # 4: C FUNDAMENTALS CLASS XII

MCQ’s (Multiple Choice Questions)


1. A character constant is a single character, enclosed:
(a) in double quotation marks (b) in single quotation marks
(c) in left and right braces (d) without quotation marks
2. The number of bytes occupied in memory by int data type is:
(a) 4 (b) 2 (c) 1 (d)8
3. The float data type occupies:
(a) 8 bytes (b) 1 byte (c) 2 bytes (d) 4bytes
4. This is a valid variable name:
(a) $amount (b) 23balance (c) marks_obt (d) printf( )
5. This is correctly initialized statement:
(a) float y =23 (b) integer y = 23
(c) Char y= ‘yes’ (d) int y = 23
6. This is a valid integer (int) type data:
(a) 32768 (b) 10.5 (c) 2560 (d) none of these
7. A string constant is a single character, enclosed:
(a) in double quotation marks (b) in single quotation marks
(c) in left and right braces (d) without quotation marks
8. Name given to variable, constants and functions are called:
(a) header files (c) identifiers (c) loops (d) structures
9. Reserved words are called:
(a) Keywords (c) Identifiers (c) data types (d) constants
10. The char data type occupies:
(a) 8 bytes (b) 1 byte (c) 2 bytes (d) 4bytes

10
CHAPTER # 4: C FUNDAMENTALS CLASS XII

Q1. Determine which of the following valid or invalid identifiers are. Give the
reason for invalid variables.

(i) Array1
Valid variable
(ii) $tax
Invalid variable name i.e. Special character ‘$’ cannot be used.
(iii) name and address
Invalid variable name i.e. White spaces cannot be used.
(iv) Include
Valid variable name
(v) Stwenty
Valid variable name
(vi) 5-numbers
Invalid variable name, special character ‘-’ cannot be used.
(vii) y/s
Invalid variable name i.e. special character ‘/’ cannot be used.
(viii) integer
Valid variable name.
(ix) f_name
Valid variable name.
(x) getch
Invalid variable name i.e. keyword cannot be used as a variable name.
(xi) smallest
Valid variable name.
(xii) ono_o_no
Valid variable name.
(xiii) 1starit
Invalid variable name i.e. variable name cannot begin with number.

11
CHAPTER # 4: C FUNDAMENTALS CLASS XII

Q2. Write appropriate declaration for following variables.


(i) Integer variables: a, b, c
int a, b, c;
(ii) Integer variable: students
int students;

(iii) Floating point variables: x, y, z


float x, y, z;
(iv) Character variables: l, m, n
char l, m, n;

Q3. Write appropriate declaration and assign the given initial values to following
variables and arrays.
(i) Integer variables: a = 485, b = 675, c = 890
int a=485;
int b=675;
int c=890;
(ii) Integer variable: students = 96854
int students = 96854;

(iii) Floating point variables: x = 0.4, y = 0.0005, z = 45.7


float x=0.4,
y = 0.0005,
z=45.7;
(iv) Character variables: l = ‘@’, m = ‘7’, n = ‘1’
char l = ‘@’;
char m = ‘7’;
char n = ‘l’;

12
CHAPTER # 4: C FUNDAMENTALS CLASS XII

Q4. Determine the following Constant type. And write the data type beside them:
(i) ‘t’

Character constant

(ii) “hellow”

String constant

(iii) 12345

Integer constant

(iv) “9”

String constant

(v) ‘1’

Character constant

(vi) 1

Integer constant

(vii) 4.567777

Floating point constant

(viii) “I am Pakistani”

String Constant

(ix) “2”

String Constant

(x) -935

Integer Constant

13
CHAPTER # 4: C FUNDAMENTALS CLASS XII

(xi) 2

Integer Constant

(xii) ‘&’

Character Constant

(xiii) “&”

String Constant

(xiv) “1.7E+23”

String Constant

(xv) 1.7E+23

Floating point Constant

Q4) Determine the following that are valid or invalid integers, float, Character and
String.

(i) Which of the following are valid or invalid integers?


(i) 15 Valid

(ii) +983.7859 Invalid

(iii) $13,786 Invalid

(iv) 78,975 Invalid

(v) 875 Valid

Which of the following are valid or invalid doubles?

(i) 15 Invalid

(ii) 983.7859 Valid

(iii) $13,786 Invalid

14
CHAPTER # 4: C FUNDAMENTALS CLASS XII

(iv) -7897I Invalid

(v) +4.1 Valid

(vi) 487.OO Invalid

(vii) 8475e–3 Valid

Which of the following are not valid char?

(i) ‘z’ Valid

(ii) ‘zz’ Invalid

(iii) “z” Invalid

(iv) ‘0’ Valid

(v) z Invalid

(vi) ‘ ’ Valid

15
CHAPTER # 4: C FUNDAMENTALS CLASS XII

ASCII:
(American Standard Code for Information Interchange) Pronounced "ask-ee," it is the built-in binary code
for representing characters. ASCII was originally developed for communications and uses only seven bits
per character, providing 128 combinations that include upper and lower case alphabetic letters, the
numeric digits and special symbols such as the $ and %.
Since the common storage unit in a computer is an 8-bit byte (256 character combinations) and ASCII
uses only the first 128 (0-127), the second set of 128 characters (128-255) are technically not ASCII, but
are typically used for foreign language and math symbols.
ASCII is entered by typing in regular text, but because there are not enough keys on the keyboard to enter
256 distinct characters, the hexadecimal (hex) numbering system is used. Hex is entered by typing only
the digits 0 to 9 or the letters A to F, and it provides a precise way of defining any of the 256 possible
combinations in the byte, whether they be control codes (0-31) or the last 128 (128-255).

Basic ASCII Character codes (All code 0 to 127)

Dec Hex Binary Char 23 17 00010111 ETB


0 00 00000000 NUL 24 18 00011000 CAN
1 01 00000001 SOH 25 19 00011001 EM
2 02 00000010 STX Dec Hex Binary Char
3 03 00000011 ETX 26 1A 00011010 SUB
4 04 00000100 EOT 27 1B 00011011 ESC
5 05 00000101 ENQ 28 1C 00011100 FS
6 06 00000110 ACK 29 1D 00011101 GS
7 07 00000111 BEL 30 1E 00011110 RS
8 08 00001000 BS 31 1F 00011111 US
9 09 00001001 HT 32 20 00100000 Space
10 0A 00001010 LF 33 21 00100001 !
11 0B 00001011 VT 34 22 00100010 "
12 0C 00001100 FF 35 23 00100011 #
13 0D 00001101 CR 36 24 00100100 $
14 0E 00001110 SO 37 25 00100101 %
15 0F 00001111 SI 38 26 00100110 &
16 10 00010000 DLE 39 27 00100111 '
17 11 00010001 DC1 40 28 00101000 (
18 12 00010010 DC2 41 29 00101001 )
19 13 00010011 DC3 42 2A 00101010 *
20 14 00010100 DC4 43 2B 00101011 +
21 15 00010101 NAK 44 2C 00101100 ,
22 16 00010110 SYN 45 2D 00101101 -

16
CHAPTER # 4: C FUNDAMENTALS CLASS XII

46 2E 00101110 . 80 50 01010000 P
47 2F 00101111 / 81 51 01010001 Q
48 30 00110000 0 82 52 01010010 R
49 31 00110001 1 83 53 01010011 S
50 32 00110010 2 84 54 01010100 T
51 33 00110011 3 85 55 01010101 U
Dec Hex Binary Char 86 56 01010110 V
52 34 00110100 4 87 57 01010111 W
53 35 00110101 5 88 58 01011000 X
54 36 00110110 6 89 59 01011001 Y
55 37 00110111 7 90 5A 01011010 Z
56 38 00111000 8 Dec Hex Binary Char
57 39 00111001 9 91 5B 01011011 [
58 3A 00111010 : 92 5C 01011100 \
59 3B 00111011 ; 93 5D 01011101 ]
60 3C 00111100 < 94 5E 01011110 ^
61 3D 00111101 = 95 5F 01011111 _
62 3E 00111110 > 96 60 01100000 `
63 3F 00111111 ? 97 61 01100001 A
64 40 01000000 @ 98 62 01100010 B
65 41 01000001 A 99 63 01100011 C
66 42 01000010 B 100 64 01100100 D
67 43 01000011 C 101 65 01100101 E
68 44 01000100 D 102 66 01100110 F
69 45 01000101 E 103 67 01100111 G
70 46 01000110 F 104 68 01101000 H
71 47 01000111 G 105 69 01101001 I
72 48 01001000 H 106 6A 01101010 j
73 49 01001001 I 107 6B 01101011 k
74 4A 01001010 J 108 6C 01101100 l
75 4B 01001011 K 109 6D 01101101 m
76 4C 01001100 L 110 6E 01101110 n
77 4D 01001101 M 111 6F 01101111 o
78 4E 01001110 N 112 70 01110000 p
79 4F 01001111 O 113 71 01110001 q

17
CHAPTER # 4: C FUNDAMENTALS CLASS XII

114 72 01110010 r 121 79 01111001 Y


115 73 01110011 S 122 7A 01111010 Z
116 74 01110100 T 123 7B 01111011 {
117 75 01110101 U 124 7C 01111100 |
118 76 01110110 V 125 7D 01111101 }
119 77 01110111 W 126 7E 01111110 ~
120 78 01111000 X 127 7F 01111111 DEL

Extended ASCII table (All code 128-255)

Dec Hex Binary Char 151 97 10010111 ù


128 80 10000000 Ç 152 98 10011000 ÿ
129 81 10000001 ü 153 99 10011001 Ö
130 82 10000010 é 154 9A 10011010 Ü
131 83 10000011 â 155 9B 10011011 ¢
132 84 10000100 ä 156 9C 10011100 £
133 85 10000101 à 157 9D 10011101 ¥
134 86 10000110 å 158 9E 10011110 ₧
135 87 10000111 ç 159 9F 10011111 ƒ
136 88 10001000 ê 160 A0 10100000 á
137 89 10001001 ë 161 A1 10100001 í
138 8A 10001010 è 162 A2 10100010 ó
139 8B 10001011 ï 163 A3 10100011 ú
140 8C 10001100 î 164 A4 10100100 ñ
141 8D 10001101 ì Dec Hex Binary Char
142 8E 10001110 Ä 165 A5 10100101 Ñ
143 8F 10001111 Å 167 A7 10100111 º
144 90 10010000 É 168 A8 10101000 ¿
145 91 10010001 æ 169 A9 10101001 ⌐
146 92 10010010 Æ 170 AA 10101010 ¬
147 93 10010011 ô 171 AB 10101011 ½
148 94 10010100 ö 172 AC 10101100 ¼
149 95 10010101 ò 173 AD 10101101 ¡
150 96 10010110 û 174 AE 10101110 «

18
175 AF 10101111 » 209 D1 11010001 ╤
176 B0 10110000 ░ 210 D2 11010010 ╥
177 B1 10110001 ▒ 211 D3 11010011 ╙
178 B2 10110010 ▓ 212 D4 11010100 ╘
179 B3 10110011 │ 213 D5 11010101 ╒
180 B4 10110100 ┤ 214 D6 11010110 ╓
181 B5 10110101 ╡ 215 D7 11010111 ╫
182 B6 10110110 ╢ 216 D8 11011000 ╪
183 B7 10110111 ╖ 217 D9 11011001 ┘
184 B8 10111000 ╕ 218 DA 11011010 ┌
185 B9 10111001 ╣ 219 DB 11011011 █
186 BA 10111010 ║ 220 DC 11011100 ▄
187 BB 10111011 ╗ 221 DD 11011101 ▌
188 BC 10111100 ╝ 222 DE 11011110 ▐
189 BD 10111101 ╜ 223 DF 11011111 ▀
190 BE 10111110 ╛ 224 E0 11100000 α
191 BF 10111111 ┐ 225 E1 11100001 ß
192 C0 11000000 └ 226 E2 11100010 Γ
193 C1 11000001 ┴ 227 E3 11100011 π
194 C2 11000010 ┬ 228 E4 11100100 Σ
195 C3 11000011 ├ 229 E5 11100101 σ
196 C4 11000100 ─ 230 E6 11100110 µ
197 C5 11000101 ┼ Dec Hex Binary Char
198 C6 11000110 ╞ 231 E7 11100111 τ
199 C7 11000111 ╟ 232 E8 11101000 Φ
200 C8 11001000 ╚ 233 E9 11101001 Θ
201 C9 11001001 ╔ 234 EA 11101010 Ω
202 CA 11001010 ╩ 235 EB 11101011 δ
Dec Hex Binary Char 236 EC 11101100 ∞
203 CB 11001011 ╦ 237 ED 11101101 φ
204 CC 11001100 ╠ 238 EE 11101110 ε
205 CD 11001101 ═ 239 EF 11101111 ∩
206 CE 11001110 ╬ 240 F0 11110000 ≡
207 CF 11001111 ╧ 241 F1 11110001 ±
208 D0 11010000 ╨ 242 F2 11110010 ≥

19
243 F3 11110011 ≤ 250 FA 11111010 ·
244 F4 11110100 ⌠ 251 FB 11111011 √
245 F5 11110101 ⌡ 252 FC 11111100 ⁿ
246 F6 11110110 ÷ 253 FD 11111101 ²
247 F7 11110111 ≈ 254 FE 11111110 ■
248 F8 11111000 ° 255 FF 11111111
249 F9 11111001 ∙

20
CHAPTER # 5: Operators and Expressions CLASS: XII

Chapter#5: Operators and Expressions


OPERATORS & OPERANDS:
Operators are needed to perform some types of mathematical calculations that transform
data into information. Therefore, we can say that “operators” are used to perform some
“operation” on the operands. For Example:
a=b+c
Here, b and c are the “operands” and operation is being performed is “addition” by using ‘+’
operator.

EXPRESSIONS:
An expression is a collection of operands (one or more) and operators (zero or more) that
can be evaluated to a single value. An operator is a constant, variable, or another expression.
The most general form of expression is:
Operand-1 operator Operand-2
For Example:
2 + 6 evaluates to 8
4 * 5 evaluates to 20
48/ 8 evaluates to 6
10 - 3 evaluates to 7
18.4 – 4 evaluates to 14.4

TYPES OF OPERATORS:
C is very rich in operators and is sometimes called “the language of operators”. It has as
many as 45 different operators. Some commonly used operators are:
1. Arithmetic operators
2. Assignment operators
3. Relational operators
4. Logical/ Boolean operators
5. Increment and Decrement operators

Arithmetic Operators:
Arithmetic operators are used to perform mathematical operations. An arithmetic
expression is made up of constants, variable, a combination of both or a function call,
connected to arithmetic operators.
Following list provides the detail about arithmetic operators.

Operator Operation Example

+ Addition a+b

- Subtraction a-b

* Multiplication a*b

1
CHAPTER # 5: Operators and Expressions CLASS: XII

/ Division a/b

% Remainder after integer division a%b

The operands can be integer quantities, floating-point quantities, or characters.


Example: Suppose that I and j are integer variables whose values are 7 and 2 respectively.
Evaluate these:
Expressions Value
i+j =9
i–j =5
i*j = 14
i/j =3
i%j =1
Example:
Suppose that f and g are floating-point variables whose values are 18.5 and 2.0,
respectively. Now Evaluates these:
Expressions Value
f+g = 20.5
f–g = 16.5
f*g = 37.0
f/g = 9.25
Example:
Suppose that c and d are character – type variables that represent the characters F and S.
Now Evaluates these:
Expressions Value
c = 70
c+d = 153
c+d+9 = 162
c + d + ‘ 9’ = 210

Order of Precedence of Arithmetic Operators:


Order of precedence determines the grouping of terms in an expression and decides how
an expression is evaluated. Certain operators have higher precedence than others; for example,
the multiplication operator has a higher precedence than the addition operator.
Operator Operation Order Associativity
Multiplication/Division/
*, /, % Higher Left to right
Remainder
+, – Addition/ Subtraction Lower Left to right

Assignment Operators:
The basic assignment operator is =. This is used to assign value of an expression to an
identifier. It has the general form:

2
CHAPTER # 5: Operators and Expressions CLASS: XII

Identifier = expression
Where “identifier” generally represents a variable and “expression” represents a constant, a
variable or combination of both.
Example:
a=5
x=y
a=b+c
area = length + breadth

Arithmetic Assignment Operators:


In addition to =, there are a number of assignment operators in C, which are called Arithmetic
assignment operators.
In arithmetic assignment operator, the arithmetic operator is combined with the assignment
operator.
The Assignment operator comes to the right of an arithmetic operator.
This operator is also known as Compound Assignment Operator
Some of them are:

Operator Operation Example Explanation


+= Add assign a+=b Same as a = a +b
–= Subtract assign a–= b Same as a = a – b
*= Multiply assign a*=b Same as a = a * b
/= Divide assign a/ =b Same as a = a / b
%= Remainder assign a%=b Same as a = a % b

For Example, the expression


i = i +5;
can be written as:
i += 5;

Example:
Suppose i and j are integer variables whose values are 5 and 6, and f and g are floating
point variables whose values are 5.5 and -3.25, evaluate them:

Expression Equivalent Expression Final Value


i += 5 i=i+5 = 10
f–=g f=f–g = 8.75
j * = (i – 3) j = j* (1 – 3) = 14
f /= 3 f=f/3 = 1.833333
i %= (j – 2) i = i % (j – 2) =0

3
CHAPTER # 5: Operators and Expressions CLASS: XII

Relational Operators:
Relational operators are used to compare two numeric operands. The operands can be
variables, constants or expressions that ultimately get evaluated to a numeric value. Characters
can be represented as integers using ASCII code; therefore, operands can be characters as well.

Operator Operation Example


< Less than a<b
> Greater than a>b
<= Less than or equal to a <= b
>= Greater than or equal to a >= b
== Equal to a == b
!= Not equal to a != b

A relational expression is made up of two arithmetic expressions connected by a relational


operator. It returns 0 when the relation is false and 1 when relation is true.
The relational operators all fall within the same precedence group, which is lower than
arithmetic operators.
For example:
a+b*c<d/f
It will be evaluated as:
(a + (b * c)) < (d / f)
Example:
Suppose that i, j, and k are integer variables whose values are 1, 2, and 3 respectively.
Evaluate them:
Expression Interpretation Value
i<j true 1
(i + j) >= k true 1
(j + k) > (i + 5) false 0
k != 3 false 0
j == 2 true 1

Difference between Equality (==) and Assignment (=) Operators:

The '==' is the so-called equality comparison operator and is used to check whether the two
expressions on both sides are equal or not. It returns true of they are equal, and false if they
are not.
The '=' is the so-called assignment operator and is used to assign the result of the expression
on the right side of the operator to the variable on the left side.

Logical / Boolean Operators:


A logical operator is also called Boolean operator. It combines the results of one or
more expression. After testing the conditions, they return either true (1) or false (0).
They logical operators are unary or binary operators. The operands may be constants, variables
or expressions. The basic logical operators are:
4
CHAPTER # 5: Operators and Expressions CLASS: XII

Operator Operation
&& Logical AND
|| Logical OR
! Logical NOT
Example:
Suppose that i is an integer variable whose value is 7, f is a floating-point variable whose
value is 5.5, and c is a character value that represents a character ‘w’. Evaluate them:
Expression Interpretation Value
(i >= 6) && (c == ‘w’) true 1
(i >= 6) || (c == 119) true 1
(f < 11) && (i > 100) false 0
(c != ‘p’) || ((i + f) <= 10) true 1

Increment and Decrement Operators:


Increment Operator ++ is used to increase the value of the variable by one
and Decrement Operator ––is used to decrease the value of the variable by one in C
programs.
Both increment and decrement operator are used on a single operand and variable, so it is
called as a unary operator. Unary operators are having higher priority than the other
operators it means unary operators are executed before other operators.
Syntax:
variable ++
variable – –
Example:
a ++
a ––
Note: Increment and decrement operators are cannot apply on constant. E.g. 4++ is invalid.

The increment or decrement operators can be of two types.

Types of Increment Operator:


1. Prefix
2. Postfix
1. Prefix (++variable)
In pre-increment first increment the value of variable and then used inside the
expression (initialize into another variable).
Example: ++a

2. Postfix (variable ++)


In post-increment first value of variable is used in the expression (initialize into
another variable) and then increment the value of variable.

Example: a++
5
CHAPTER # 5: Operators and Expressions CLASS: XII

Types of Decrement Operator:


1. Prefix
2. Postfix

1. Prefix (-- variable)


In pre-decrement first decrement the value of variable and then used inside the expression
(initialize into another variable).

Example: --a

2. Postfix (variable --)


In Post-decrement first value of variable is used in the expression (initialize into another
variable) and then decrement the value of variable.

Example: a--

Example:
Suppose i and j are integer variables whose values are 3 and 5 respectively. Evaluate
them:

j = i++; // j now = 3 and i = 4 postfix increment//


j = ++i; // j now = 5 and i = 5 prefix increment //
j = i --; // j now = 5 and i = 4 postfix decrement //
j = -- i; // j now = 3 and i = 3 prefix decrement //

6
CHAPTER # 5: Operators and Expressions CLASS: XII

LIBRARY FUNCTIONS:
Library functions in C language are built-in functions which are grouped together and placed
in a common place called library. Each library function in C performs specific operation.
Functions are available in a number of libraries. These are accessed by including header
files in your code; the header file is a pointer/reference to the library.
Some of the common library functions provided with most C compilers are listed in the table
below:
Function Description Header File
abs(i) Return the absolute value of i stdlib.
cos(d) Return the cosine of d math.h
exp(d) Raise e to the power d (e=2.7182818… is the math.h
base of natural logarithm).
fabs(d) Return the absolute value of d. math.h
getchar(c) Enter a character from standard input device stdio.h
putchar(c) Send a character to standard output device stdio.h
scanf(…) Enter data items from standard input device stdio.h
printf(…) Send data items to standard output device stdio.h
sin(d) Return the sine of d math.h
sqrt(d) Return the square root of d math.h
pow(d1, d2) Return d1 raised to the d2 power math.h
tan(d) Return the tangent of d math.h
tolower(c) Convert letter to lowercase ctype.h
toupper(c) Convert letter to uppercase ctype.h

Definitions of Library Functions:


(a) pow( ):
The function pow() is used to calculate the power raised to the base value. It takes two
arguments. It returns the power raised to the base value. It is declared in “math.h” header file.
Syntax: pow(d1, d2)
(b) sqrt( ):
The function sqrt( ) is used to return the square root of d. It is declared in “math.h”
header file.
Syntax: sqrt(d)
(c) abs( ):
The function abs( ) is used to return the value of i. It is declared in “stdlib.h” header
file.

Syntax: abs(i)

7
CHAPTER # 5: Operators and Expressions CLASS: XII

Questions:
1. Describe Operators and Operands with the help of example.
2. Define the term expression with few examples.
3. Write the classification of operators.
4. How many types of operators in C? Name them.
5. Define Arithmetic operators. Also explain them with examples.
6. What is Order of Precedence? Write the precedence of arithmetic operators.
7. Explain Assignment operator with the help of examples.
8. Explain Relational Operators with the help of examples.
9. Explain the difference between Equality(= =) and Assignment (=) Operators.
10. Explain Logical/Boolean Operators with the help of examples.
11. Explain Increment and Decrement Operators with their types.
12. What are the Library Functions in C-language? Make list of some of the common
library functions.
13. Define the following functions.
(a) pow( ) (b) sqrt( ) (c) abs( )

8
CHAPTER # 5: Operators and Expressions CLASS: XII

MCQ’s (Multiple Choice Questions)

1. This arithmetic operator computes the integer remainder:


(a) % (b) + (c) – (d) /
2. “=” is an operator of this type:
(a) Logical (b) Assignment (c) Arithmetic (d) Relational
3. This operator has the lowest precedence:
(a) * (b) % (c) < (d) &&
4. This is the output of 4 % 5:
(a) 0 (b) 1 (c) 4 (d)
5. A relational operator is used to:
(a) Combine values
(b) compare values
(c) distinguish different types of variable
(d) change variables to logical values
6. Precedence determines which operator
(a) is most important (b) is used first
(c) is fastest (d) operates on the largest number
7. It is not an arithmetic operator:
(a) + (b) – (c) % (d) <=
8. An operator is used to compare the values between two operands:
(a) Logical (b) Relational (c) Arithmetic (d) Assignment
9. || is the type of operator:
(a) Logical (b) Arithmetic (c) Relational (d) Address
10. This is not a relational operator:
(a) && (b) >= (c) == (d) <
11. This is an arithmetic operator:
(a) + (b) & (c) && (d) <
12. This is a relational expression:
(a) x = y; (b) x == y; (c) x + y; (d) x ++;

9
CHAPTER # 5: Operators and Expressions CLASS: XII

Answer the following:

 Suppose that a, b, and c are integer variables that have been assigned the values
8, 3, and -5 respectively. Evaluate each of the following arithmetic expressions:

Expressions Answers

o a+b+c 6
o 2 * b + 3 * (a – c) 45
o a/b 2.66
o a/c -1.6
o a%b 2
o a*b/c 4.8
o a * (b / c) 4.8

 Suppose that a, b, and c are floating point variables whose values are 8.8, 3.5, and
-5.2 respectively. Evaluate each of the following arithmetic expressions:

Expressions Answers

o a+b+c 7.1
o 2 * b + 3 * (a – c) 143.0
o a/b 2.514285
o a/c -1.69230
o a / (b + c) -5.176470
o (a / b) +c -2.685714
o 2 * a /3 * b -20.533333

10
CHAPTER # 5: Operators and Expressions CLASS: XII

 Evaluate following expressions independent of each other, Assume that i, j, k are


integers with values 3, 4, and 2 respectively.

Expressions Answers
o i++ – j –– -1
o i––% j ++ 3
o j++ / i–– 2
o k++ * ––i 4
o i–1%j+1 3
 Interpret the following expressions and write values (answers) as 0 or 1, Assume
that i = 1, j = 2, k = 3.
Expressions Values
o i<j 1
o (i + j)> = k 1
o (j + k) > (i + 5) 0
o k! = 3 0
o j==2 1

 Convert the following algebraic expressions into C – equivalent format:


1
o x = a4 x = (½)*pow(a,4)
2

−𝑏+√𝑏2 −4𝑎𝑐
o x= x = (-b + sqrt((b*b)-(4*a*c)))/(2*a)
2𝑎

o y = |b2 – 4ac| y = fabs((b*b)-(4*a*c))

(2ab)2
o x= x = pow(2*a*b,2)/(3*c)
3𝑐

4
o y = π r3 y = (4.3)*3.142*pow(r,3)
3

(a2 – b2)2
o z= z = pow((a*a-b*b),2)/(a-b)
(𝑎−𝑏)

11
CHAPTER # 5: Operators and Expressions CLASS: XII

o x = (x + y)n x = pow(x+y , n)

o x = (√a2 + b2)2 x = pow(sqrt((a*a)+(b*b)),2)

o A = π r2 A = 3.142*r*r

o x = 3ab3+ 3a2b x = 3*a*pow(b,3) + 3*a*a*b

o y = a2 + b3 + c4 y = a*a + pow(b,3) + p(c,4)

b2 – c3
o x= x = ((b*b) – pow(c,3))/(2*b*c)
2𝑏𝑐

o x = √𝑥 + 𝑦 + z3 x = sqrt(x+y) + pow(z,3)

(4𝑎+3)
o (4*a+3)/(2*y*y+2*z+2)
(2𝑦 2 +2𝑧+2)

o A = (x2 + y2) – (x – y)3 A= (x*x + y*y) – pow(x-y,3)

12
CHAPTER # 6: INPUT AND OUTPUT STATEMENT CLASS: XII

Chapter#6: Input and Output Statements


Input and output statements of computer languages are used to provide the communications
between the user and the program. In Turbo C++, the input and output operations are carried
out through built-in functions. Data can be read from keyboard or displayed on monitor
through these functions.

Input/ output functions can be classified as:


Input/ Output Functions

Formatted Functions
Unformatted Functions
Type Input Output
Type Input Output
char scanf( ) printf( )
getch( )
putch( )
int scanf( ) printf( ) char getche( )
putchar( )
Float scanf( ) printf( ) getchar( )
string scanf( ) printf( ) Int - -

Float - -

string gets( ) puts( )

FORMATTED I/O FUNCTIONS:


The scanf( ) and printf fall under the category of formatted input and output functions
respectively. The ‘f’ in the scanf and printf stands for formatted. These functions instruct the
compiler how to interrupt the various values of input data and how to obtain the output in the
specified form.
 The scanf( ) Function
The scanf( ) function is the most versatile input function because it can handle all of the
different variables and control their formatting. This function can be used to enter any
combination of numeric, character, and string variables all at the same time.
The general form of scanf( ) is:
scanf(“control string”, variable list);
The control string contains the format specifiers indicating how the data input will be
interrupted. The variable list indicates the variable that will hold the input values.

1
CHAPTER # 6: INPUT AND OUTPUT STATEMENT CLASS: XII

 The printf( ) Function:


The printf( ) is the most versatile output function because it can display data of all types and
can work with multiple arguments. This function can be used to output any combination of
numerical values, single characters and strings. printf( ) can format how the data appears.
The general form of printf( ) is:
printf(“ control string”, variable list);
The control string contains format specifiers indicating how the data output will be
interpreted. The variable list indicates the variables that will hold the output values.

Format Specifier:
The format specifier is used during input and output. It is a way to tell the compiler
what type of data is in the variable during taking input using scanf( ) or printing using printf(
). Each format specifier starts with the percent symbol (%) followed by a letter indicating
the data type.

Specifier Meaning
%d Inputs or displays an integer number
%u Inputs or displays an unsigned integer
%f Inputs or displays a float
%e Inputs or displays number in scientific
notation
%c Inputs or displays a character
%s Inputs or displays a string
%o Inputs or displays an octal number
(unsigned)
%x Inputs or displays a hexadecimal number
(signed)

C-Language Program Examples for printf( ) and scanf( ) functions


Example#1: Example#2:
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main(void) void main(void)
{ {
clrscr( ); clrscr( );
int num; char letter;
printf(“Enter any number : ”); printf(“Enter a letter : ”);
scanf(“%d”,&num); scanf(“%c”,&letter);
getch( ); getch( );
} }

2
CHAPTER # 6: INPUT AND OUTPUT STATEMENT CLASS: XII

Example#3: Example#4:
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main(void) void main(void)
{ {
clrscr( ); clrscr( );
int fnum; char name[10];
printf(“Enter any number : ”); printf(“Enter your name : ”);
scanf(“%f”,&fnum); scanf(“%s”,&name);
getch( ); getch( );
} }

Example#5: Example#5:
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main(void) void main(void)
{ {
clrscr( ); clrscr( );
int a, b, c, d; int i;
printf(“Enter four integers: “); float b;
scanf(“%d %d %d %d”, &a, &b, &c, &d); char c;
printf(“%d, %d, %d, %d”, a,b,c,d); char string[10];
getch(); printf(“Enter all data types: “);
} scanf(“%d %f %c %s”, &i, &f, &c, string);
printf(“%d, %f, %c, %s”, i,f,c,string);
getch();
}

UNFORMATTED I/O FUNCTIONS:


There are several standard library functions available for unformatted input and
output. Some of them deal with a single character and some can deal with a string of characters.
Few more input out functions are discussed below:

 Single Character Input:


The Input functions in C which can handle single character only are called single character
input functions. Three most common input functions are:
o The getchar( ) Function:
The function getchar( ) stands for “get character” and input a single character from a
keyboard. You can input the character as either a char or int type because getchar( )
function treat characters as integers and accept ASCII value of characters.

int letter; char letter


letter = getchar( ); OR letter = getchar( );

3
CHAPTER # 6: INPUT AND OUTPUT STATEMENT CLASS: XII

o The getch( ) and getche( ) Functions:


The getch( ) and getche( ) are two very similar functions. The “get” means it gets
some input and “ch” means it gets a character. The difference between two functions
is that the function getche( ) echoes (displays) the character that you typed to the
screen (the letter “e” in getche( ) stands for echo) whereas getch( ) just returns the
character that you typed without echoing it on the screen.

Example:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr( );
char ch;
// the character is displayed when pressed
printf(“Enter a character: ”);
ch = getche( );

// the character is not displayed when pressed


printf(“\nEnter a character: ”);
ch = getch( );

getch( );
}

 Single Character Output:


The Functions we use to output single character only are called Single character Output
Functions. C contains many functions that can handle single character output. Two most
popular output functions are putchar( ) and putch( ).

o The putchar( ) and putch( ) Functions:


The function putchar( ) stands for “put character” and displays only a single char
value on the screen. The char can be a character variable or the character itself
contained in single quotes.

The function putch( ) has same effect as putchar( ).

1. A char Constant:
putchar(‘T’);

2. A Variable Constant:
char ch = ‘p’;
putchar(ch);

4
CHAPTER # 6: INPUT AND OUTPUT STATEMENT CLASS: XII

Example: Example:
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main(void) void main(void)
{ {
clrscr( ); clrscr( );
char ch=’P’ putchar(‘A’);
putch(ch); putch(‘\n’); //blank line
putchar(ch); putchar(‘B’’);
putch(‘A’); getch();
putchar(‘A’); }
getch();
} Output:
Output: A
PPAA B

 String Input:
C contains a number of library functions to input text strings. The most common method is
the use of gets( ) function which is smaller and faster as compared to the formatted input
functions.
o The gets( ) Function:
The function gets( ) stands for “get string”. It reads a string from the keyboard and
assigns it to the required variable, which comes as an argument of the function.
char name[10];
gets(name);

 String Output:
C contains a number of library functions to output text strings. The most common method
is the use of puts( ) function which is smaller and faster as compared to the formatted output
functions.
Turbo C++ perform a new-line command after the puts( ) function. This means that after
the data is displayed, the cursor will move to the start of the next line.

o The puts( ) Function:


The function puts( ) stands for “put string” and displays a string on the monitor.
The argument must be one of these:

1. A string constant:
puts(“Best Wishes”);

2. A string variable:
char greet[30]= “Best Wishes”;
puts(greet);

5
Example:
void main(void) Output:
{
Best Wishes
char greet[30] = “Best Wishes”;
Best Wishes
puts(greet);
Hello World
puts(“Best Wishes”);
puts(“Hello World”); }

6
Questions:
1. What are the commonly used input/output functions in C language? Enlist them.
(Short)
2. Describe the formatted I/O functions with the help of examples. (Long)
3. Define Format specifier. Enlist the various format specifiers and also write their
descriptions. (Long)
4. How many unformatted single character input/output functions in C language?
(Short)
5. Define unformatted single character input functions used by C language with the
help of examples. (Long)
6. What is the main difference between getch( ) and getche( ) function? (Short)
7. Describe unformatted single character output functions used in C-language with the
help of example. (Long)
8. Describe Unformatted String input function with the help of example. (Short)
9. Describe Unformatted String output function with the help of example. (Short)

7
Multiple Choice Questions (MCQ’s)

1. This function is used to write on to the computer screen:


(a) main( ) (b) clrscr( ) (c) printf( ) (d) getch( )
2. Let a = 0, the statement printf (“%d”, a++), will print this value:
(a) 0 (b) 1 (c) 2 (d) 3
3. This is the format specifier for “int” variable:
(a) %x (b) %c (c) %d (d) %f
4. A function is used to get only a character from a keyboard:
(a) getche( ) (b) printf( ) (c) scanf( ) (d) gets( )
5. A function is used to get any data as an input from keyboard:
(a) getche( ) (b) printf( ) (c) scanf( ) (d) gets( )
6. What will be the output of the following statement?
printf(“%.2f”, 633.5584);
(a) 63.33 (b) 63 (c) 633.55 (d) none of these
7. Which format specifier is used for double data type?
(a) %d (b) %f (c) %c (d) %lf
8. To use scanf and printf, header file must be included:
(a) stdio.h (b) math.h (c) string.h (d) alloc.h
9. scanf( ) is a/an:
(a) formatted input function (b) formatted output function
(c) unformatted input function (d) unformatted output function
10. format specifier must start with:
(a) % (b) & (c) / (d) \

8
 Write printf( ) statements for the following output:

Hello
How are you?
I am fine, you tell.

Source Code:
printf(“Hello”);
printf(“\n\tHow are you?”);
printf(“\n\tI am fine, you tell,”);

 What will be the output of the following program:


void main(void) Output:
{
My name is
puts(“My name is”);
Naheed
puts(“\n”);
puts(“Naheed”);
}

 Use single character output functions for the following output:

1
2
3
A

Source Code:
putchar(‘1’);
putchar(‘\n’);
putchar(‘2’);
putchar(‘\n’);
putchar(‘3’);
putchar(‘\n’);
putchar(‘A’);

9
 Find and write the error of the following program and also it in a debugged form:

Void main viod void should be in parenthesis after main


( ‘{’ should be written instead of ‘(‘
prinf(“This is my First C program), missing double quotes(“) and semi colon (;)
) ‘}’ should be written instead of ‘)’

Rewrite the code:


void main(void)
{
printf(“This is my First C program”);

 Find and write the error of the following program and also write it in a debugged
form:
void main (void)
{
printf(“ “This is a string” ”) missing semi colon(;) and escape sequence (\”)
}

Rewrite the code:


void main(void)
{
printf(“\“This is a string\””);
}

 Find and write the error of the following program and also write it in a debugged
form:

void main (void)


[ use ‘{’ bracket instead of ‘[’ bracket.
printf(Enter a Character”); double quotes are missing
scanf(“%d”, &‘c’) terminator (;) is missing
}

Rewrite the code:

void main (void)


{
Printf(“Enter a Character”);
scanf(“%d”, &‘c’);
}
10
 What will be the output of the following program:
void main(void) Output:
{ My name is
puts(“My name is\n”); Naheed
puts(“Naheed\n”);
}

 Write the output for the following program.


Source code: Output:
void main (void)
{ Name = Hania Wahid
int age = 17; Gender = F
float height = 5.1; Age = 17
char gender = ‘F’; Height = 5.1
char name[10] = “Hania Wahid”;
printf(“Name = %s”, name);
printf(“\nGender = %c”, gender);
printf(“\nAge = %d”, age);
printf(“\nHeight = %.1f”, height);
}

 Write the source code for the following output by using format specifiers.
Output: Source code:
34 printf(“%d”34);
35.666 printf(“\n%.3f”,35.666);
Hellow printf(“\n%s”,”Hellow”);
@ pritnf(“\v%c”,‘@’);

 Write the output for the following statements:


printf(“%d”, 678); Output:
printf(“\n\t %.2f”, 45.678); 678
printf(“\n%c”, ‘A’); 45.67
printf(“\t %s”, “Hello”); A Hello

11
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

Chapter#8: Iteration Control Structures


ITERATION CONTROL STRUCTURE:
Iteration is often referred to as a loop, because the program will keep repeating the
activity until the condition becomes false. Loops simplify programming because they
enable programmer to specify certain instructions only once and computer has to
execute them many times.
There are three types of iteration control structures in programming languages:
1. For loop
2. While loop
3. Do-while loop

The for loop:


The for loop is used to repeat a statement or a block of statements for a specifies number
of times. The for loop includes the initialization of the counter, the condition, and the
increment.
The general form of the for loop statement:
for(initialization expression; test expression; increment expression)
statement;
For example, this program uses a for loop to print numbers from 1 to 10.
void main(void)
{ Output:
clrscr( );
1 2 3 4 5 6 7 8 9 10
int count;
for(count=1;count<=10;count++)
printf(“%3d “,count);
getch( );
}

Nested for loops:


When one for command is performed within another, they are said to be nested. The
inside loop is completely repeated for each repetition of the outside loop.
Example:
void main(void) Output:
{
clrscr( ); **********
**********
int row, column; **********
for(row = 1; row<=5; row++) /* outer loop */ **********
{ **********
for(column =1; column<=10; column++) /* inner loop */
printf(“*”);
printf(“\n”);
}

1
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

getch( );
}

The While Loop:

The while loop allows the programmer to specify that an action is to be repeated while
some condition remains true. It is used when the exact number of loop repetitions are not
known before the loop execution begins.
The general form of the while statement is:
while(condition)
statement;

Consider the example:

void main(void)
{
clrscr( );
char ch;
printf(“Enter a character: ”);
ch = getche( );
while(ch!=‘q’)
{
printf(“\nCharacter = %c”,ch);
printf(“\nEnter a Character: “);
ch = getche( );
}
getch( );
}

Nested While Loop:


The while loop can be nested just like a for loop. The following program shows a while
loop nested within another while loop.
void main(void)
Output:
{
clrscr( ); **********
int row =1, column=1; **********
**********
while(row<=5) /* outer loop */ **********
{ **********
while(column<=10) /* inner loop */
{
printf(“*”);
column++;
}
2
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

printf(“\n”);
row++;
}
getch( );
}

The do-while Loop:


In do-while loop, the test condition is at the bottom of the loop. This means that the
program always executes the statement(s) at least once, even if the condition fails for the
first time itself. Then, it depends on the value of the test expression, to continue the do-while
loop.
The general form of the do-while statement is:
do
statement;
while(condition);

For Example:
void main(void)
{
clrscr( );
int count =1;
do
{
printf(“%3d”, count);
}
while(++count<=10)
getch( );
}

The break Statement:


The break statement allows you to exit a loop or switch from any point within its body,
bypassing its normal termination expression. It is used within any C control structure; e.g. for,
while, do-while, if, or switch statement.
The continue Statement:
The continue statement is just the opposite of the break statement. It takes the control
to the beginning of the loop, bypassing the statements inside the loop.
Let’s consider the output of both examples:

3
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

Example # 1:
void main(void) Output:
{ 1 2 3 4
clrscr( );
int i;
for(i = 1; i<=10; i++)
{
if(i ==5)
break;
printf(“%3d”, i);
}
getch( );
}

Example # 2: Output:
void main(void)
{ 1 2 3 4 6 7 8 9 10
clrscr( );
int i;
for(i = 1; i<=10; i++)
{
if(i ==5)
continue;
printf(“%3d”, i);
}
getch( );
}

Difference between while and do-while loop

The main difference between a while loop and do while loop is that while loop check
condition before iteration of the loop, whereas do-while loop, checks the condition after the
execution of the statements inside the loop.

4
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

Program Examples for FOR-LOOP and NESTED FOR-LOOP:

Example # 1: Write a program that generates even numbers from 1-20.


#include<stdio.h>
#inlcude<conio.h>
void main(void)
{
clrscr( );
int i;
for(i=1; i<=20; i++)
{
if((i%2)==0)
printf(“%d\n”,i);
}
getch( );
}

Example # 2: Write a program to print the sum of odd numbers from 1 to 100, i.e.
sum = 1 + 3 + 5 + 9 + … + 99
#include<stdio.h>
#inlcude<conio.h>
void main(void)
{
clrscr( );
int i, sum=0;
for(i=1; i<100; i=i+2)
sum = sum + i;
printf(“\n\n\nThe sum is = %d”, sum)
}
getch( );
}

Example # 3: Write a program which generates the following output:


*
**
***
****
*****

5
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

#include<stdio.h>
#inlcude<conio.h>
void main(void)
{
clrscr( );
int row, column;
for(row = 1; row< = 5; row++)
{
for(column = 1; column < = 5; column ++)
printf(“*”);
printf(“\n”);
}
getch( );
}

Example # 4: Write a program which reads a number and prints its factorial using for
loop:

#include<stdio.h>
#inlcude<conio.h>
void main(void)
{
clrscr( );
int num, fact = 1;
printf(“Enter number to find its factorial: ”);
scanf(“%d”, &num);
for(int i = 1; i<=num;i++)
fact = fact * i;
printf(“\n\nThe factorial of %d is %d”, num, fact);
getch( );
}

6
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

Program Examples for WHILE LOOP:

Example # 1: Write a program which reads and writes a character until the inputted
character is ‘q’.

#include<stdio.h>
#inlcude<conio.h>
void main(void)
{
clrscr( );
char ch;
printf(“Enter any character: ”);
ch = getche( );
while(ch != ‘q’)
{
printf(“\n Character = %c”, ch);
printf(“\n\n Enter a character: ”);
ch = getche( );
}
getch( );
}

Example # 2: Write a program which prints your name ten times using while loop.

#include<stdio.h>
#inlcude<conio.h>
void main(void)
{
clrscr( );
int i = 1;
while(i<=10)
printf(“\nyour name”);

getch( );
}

7
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

Questions:
1. What is iteration Control structure? And enlist the iteration control structures in
programming languages? (Short)
2. What is for loop used for? Write its general form with example. (Long)
3. Define nested for loop with suitable example. (Short)
4. What is while loop? When is it used? Write its general form with example. (Long)
5. Write a program using nested while loop. (Short)
6. Define the ‘do-while loop’ and also write its general statement with suitable example.
(Long)
7. What is break and continue statement used for? Describe them with example. (Long)
8. What is the major difference between while and do-while loop? (Short)

Multiple Choice Questions (MCQ’s)


1. For ( ) loop is used when we need to perform:
(a) Sequential Logic (b) Selection Logic
(c) Iteration Logic (d) Parallel logic
2. This loop is used for definite repetition:
(a) for (b) while (c) do-while (d) repeat-until
3. This loop executes atleast once:
(a) for (b) while (c) do-while (d) none of these
4. The loop within a loop is known as:
(a) Recursive loop (b) Nested loop (c) Simple loop (d) complex loop
5. Which of the following control structures uses DO-WHILE:
(a) Sequence Logic (c) Selection Logic
(c) Iteration Logic (d) none of these
6. All three expressions of for loop must be separated by:
(a) , (b) ; (c) & (d) “
7. This statement can terminate any loop immediately:
(a) continue (b) switch (c) break (d) none of these
8. This is not a loop:
(a) for (b) while (c) do-while (d) switch
9. The statement for(x=0; x<1; x++) printf(“x=0”):
(a) is an infinite loop (b) will never output
(b) causes a syntax error (d) will output once
10. The while and do-while loops are used for:
(a) definite repetition (b) indefinite
(c) execute once (c) none of these

8
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

 Convert the following program in while( ) equivalent.


void main(void)
{
int a = 3;
do
{
printf(“%d\n”,a);
a = a+3;
}
while(a<=10);
}

Conversion:
void main(void)
{
int a = 3;
while(a<=10)
{
printf(“%d\n”,a);
a = a+3;
}
}
 What will be the output of the following C-language program?
for(i=5; i > 0; i--)
{
for(j=1;j<=i;j++)
printf(“%d”,i);
printf(“\n”);
}
Output:

55555
4444
333
22
1

9
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

 Write a program which prints all the ASCII characters from 0 to 255.
use two methods:
i. for-loop
ii. while-loop

for-loop:
#include<stdio.h>
#inlcude<conio.h>
void main(void)
{
clrscr( );
int i;
for(i=0; i<=255; i++)
printf(“%d\t%c\n”,i,i);
getch( );
}
while-loop:
#include<stdio.h>
#inlcude<conio.h>
void main(void)
{
clrscr( );
int i=0;
while(i<256)
{
printf(“%d\t%c\n”,i,i);
i++;
}
getch( );
}

10
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

 Write a program which generates the table of any inputted number.

Source Code:
#include<stdio.h>
#inlcude<conio.h>
void main(void)
{
clrscr( );
int num, i;
printf(“Enter any number: ”);
scanf(“%d”,num);
for(i=1; i<=10; i++)
printf(“%d * %d = %d\n”, num, i, num*i);
getch( );
}

 Write the output of the following statement of C-language program.


for(int i=2; i<10; i++)
{
printf(“%d”,i);
if(i%2==0)
continue( );
printf(“\n”);
}
Output:

23
45
67
89

11
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

 Write a program in C-language to print number from 4 to 9 and their squares.


(Using do while loop)

Program:
void main(void)
{
int i=4;
do
{
printf(“%d\t%d\n”, i, i*i);
i++;
}
while(i<10);
}

 Write the equivalent code of the following in while loop format.


for(a=1;a<=100;a++)
printf(“%d\n”,a*a);

while-loop:
int a=1;
while(a<=100)
{
printf(“%d\n”,a*a);
a++;
}

12
CHAPTER # 8: ITERATION CONTROL STRUCTURES CLASS: XII

 What will be the output of the given program statements?


for(int x = 1; x<=5; x++)
{
for(int y = 1; y<=5; y++)
printf(“%d”, y);
printf(“\n”);
}

Output:
12345
12345
12345
12345
12345

 What will be the output of the following statement?


for(int a =1; a<=10; a++)
printf(“%3d”,pow(a,2));

Output:

1 4 9 16 25 36 49 64 81 100

13
CHAPTER # 9: FUNCTIONS CLASS: XII

Chapter # 9: Functions
FUNCTIONS:
A function is a block of instructions that together perform a specific task. Every C
program has at least one function, main( ). You can also write your own functions and use
them just as you use functions in a C library.

Characteristics of function:
1. The complexity of the entire program can be divided into simple subtasks.
2. Functions help us to avoid unnecessary repetition of code. Function can be used many
times in the same program.
3. A function can be shared by other programs by compiling it separately and loading
them together.
4. Functions can have inputs and outputs and can process information.
5. In Turbo C++, a function can call itself again and again.

CLASSIFICATION OF FUNCTIONS:
Functions are of two types.
These are:
1. Built-in Functions/ Library Functions
2. User-defined Functions

Built-in Functions:
Many of the operations, like taking the square root of a number, sin value of a number,
etc., will be frequently used by many programmers in their programs. These functions are
called Library Function or Built-in Functions

Some of the commonly used mathematical library functions:

Function Library File Purpose: Example Argument(s) Result


Returns the absolute value of its integer
abs(x) <math.h> int int
argument; if x is -5, abs(x) is 5.
Returns x raise to the power of y. if x is
pow(x,y) <math.h> negative, y must be a whole number; if x double double
is 0.16 and y is 0.5, pow(x,y) is 0.4
Returns the non-negative square root of x
sqrt(x) <math.h> double double
(√x) for x≥0.0; if x is 2.25, sqrt(x) is 1.5.

User-defined function:
Apart from the library functions that are built-in, users can also define functions to do a
task relevant to their program; such functions are called user-defined functions. These
functions should be codified by the user, so that any call to the function can refer to it.

1
CHAPTER # 9: FUNCTIONS CLASS: XII

User-defined functions must require three things:


1. Function declaration or function prototype
2. Function definition
3. Function calling.

General Form of Function:


#include<stdio.h>
#include<conio.h>
int y = 4; global variable
void display(void); function declaration or function prototype
void main(void)
{
clrscr( );
display( ); function calling
getch( );
} function name
void display(void) accept
function { data type
header int i,j;
for(i=1;i<=5;i++) Function
return { definition
data type for(j=1;j<=x;j++) for
printf(“*”); display()
Body of printf(“\n”);
function }
}
Function Prototype:
Using functions in your program requires that, you first declare the function and then
you define the function. The declaration of a function is called its prototype. It is a line written
before the main( ) function. The prototype tells the compiler in advance.
The general structure of the function prototype is:
type function_name (type argument-1, argument-2, …);
It has three main components. These are:
1. Data type of the function
2. Name of the function
3. Arguments

2
CHAPTER # 9: FUNCTIONS CLASS: XII

Function Definition:
The function definition is a function itself. The general structure of the function
definition is:
type function_name (type argument-1, argument-2, …)
{
body of function;
}
The function definition has two parts:
1. Function Header
2. Body of Function

Function Calling:

A user defined function is called from the main program simply by using its name,
including the parenthesis which follows the name.
Syntax: function_name( );
Example: add( );

If function returns a value, then we can store return value to a variable in the calling function.
Example: x = add( x , y)

Argument:
Sending data to a function is called passing arguments; sending variables, constant, or
expression whose values are needed by the function. The arguments are the input data that the
function needs to compute its result.
Some examples of prototypes of user-defined functions are:
void display(void);
int average(void);
void subset(int x);
float big_pow(double x, double y);

3
CHAPTER # 9: FUNCTIONS CLASS: XII

Example1: Write a program which passes an argument to user-defined function as table


number and prints the table of that argument.

#include<stdio.h>
#include<conio.h>
void table(int num);
void main(void)
{
clrscr( );
int n;
printf(“\t\t\t******PRINTING TABLE********\n\n”);
printf(“Enter any number: ”);
scanf(“%d”,&n);
table(n);
printf(“Enter any number: ”);
scanf(“%d”,&n);
table(n);
getch( );
}
void table(int num)
{
for(int i=1;i<=10;i++)
printf(“%d * %d = %d\n”,num,i,num*i);
}

Example2: Write a program that prints area of rectangle by passing multiple arguments
to a user-defined function.

#include<stdio.h>
#include<conio.h>
void rectangle(float width, float height);
void main(void)
{
clrscr( );
float w, h;
printf(“Enter width of rectangle: ”);
scanf(“%f”,&w);
printf(“Enter height of a rectangle: ”);

4
CHAPTER # 9: FUNCTIONS CLASS: XII

scanf(“%f”,&h);
rectangle(w,h);
getch( );
}
void rectangle(float width, float height)
{
float area;
area = width*height;
printf(“Area of rectangle = %f”,area);
}
Example3: Write a program that prints different sizes of rectangle and square by passing
multiple arguments to a user-defined function.
#include<stdio.h>
#include<conio.h>
void rectangle(int width, int height);
void main(void)
{
clrscr( );
printf("rectangle(7,4)\n");
rectangle(7,4);
printf("\nrectangle(8,4)\n");
rectangle(8,4);
printf("\nrectangle(2,1)\n");
rectangle(2,1);
printf("\nrectangle(7,8)\n");
rectangle(7,8);
getch( );
}
void rectangle(int width, int height)
{
int i,j;
for(i=1;i<=height;i++)
{
for(j=1;j<=width;j++)
printf("\xDB");
printf("\n");
}
}

5
CHAPTER # 9: FUNCTIONS CLASS: XII

 Write a program that passing three arguments and return the maximum value of
argument by using user-defined function.

#include<stdio.h>
#include<conio.h>
int max(int a, int b, int c);
void main(void)
{
clrscr( );
int x, y, z;
printf("Enter First Number: ");
scanf(“%d”,&x);
printf("Enter First Number: ");
scanf(“%d”,&y);
printf("Enter First Number: ");
scanf(“%d”,&z);
printf(“The maximum number: %d”, max(x,y,z));
getch( );
}

int max(int a, int b, int c)


{
int maximum;
if(a>b&&a>c)
maximum= a;
else if(b>a&&b>c)
maximum = b;
else
maximum = c;
return maximum;
}

6
CHAPTER # 9: FUNCTIONS CLASS: XII

 Write a function that returns the value of factorial of inputted number by using
function.

#include<stdio.h>
#include<conio.h>
int fact(int n);
void main(void)
{
clrscr( );
int num;
printf("Enter a Number: ");
scanf(“%d”,&num);

printf(“The factorial of %d is: %d”, num, fact(num));


getch( );
}

int fact(int n)
{
int f=1;
for(i=n;i>=1;i--)
f = f*I;
return f;
}

7
CHAPTER # 9: FUNCTIONS CLASS: XII

Questions:
1. What is function? Write the characteristics/importance/advantages of functions. (Short)
2. What is a built-in function? Explain with examples. (Short)
3. What is a user-defined function? (Short)
4. Write the general form of a function. (Long)

8
CHAPTER # 9: FUNCTIONS CLASS: XII

Multiple Choice Questions (MCQ’s)

1. A function is a:
a. Header file b. block of code c. library d. none of them
2. A global variable is defined in a declaration:
a. In main( ) only b. in the first function that uses it
c. in any function that uses it d. outside of any function
3. Use the ____________ data type when the function does not return a value.
a. int b. float c. char d. void
4. A function that calls itself is called a:
a. recursive function b. function calling
c. function d. all of them
5. Every C program must have this function:
a. scanf( ) b. getch( ) c. main( ) d. printf( )
6. All variables declared in function definition are called:
a. Local variables b. Instance variable
c. Static variables d. Global variables
7. Which is not a built-in function?
a. pow( ) b. sqrt( ) c. sin( ) d. average( )
8. A function prototype is also known as:
a. Function call b. Function definition
c. Function header d. Function declaration
9. int average(int a, int b, int c) In this function declaration, , how many parameters are
passed?
a. 1 b. 2 c. 3 d. 4
10. The functions that are defined by the programmer are called:
a. Built-in function b. User-defined Function
c. Sub-function c. Function

9
CHAPTER # 14: DATA FILES CLASS: XII

Chapter # 14: Data Files


A file is a complex data type that is stored external to main memory, usually on disk. Files are
created in several ways: with editors or word processors, by programs, or by other programs.
A program may read or write to a file. C provides special commands for file operations.

C files can be thought of as a list of characters that include newline, spaces, tabs, letters,
numerals punctuation marks, and control characters. Similar to the editor program in which the
<enter> key causes a newline character (presented by C as ‘\n’) to be placed in the file.

Declaring a File:

The header file <stdio.h> contains a number of constructs that pertain to files. Among there is
the identifier FILE. It is a constant and so it is written with uppercase letters.

To declare a file, use this syntax

FILE *file_pointer;

Where keyword FILE is a structure type that establishes the memory buffer and file_pointer is
a pointer variable that indicates the beginning of this buffer.

If you want to use more than one file simultaneously, use this syntax:

FILE *infile, *outfile;

Opening a File:

The link between your program, the file, and the computer is established with fopen( ) function,
using the syntax:

pointer = fopen(“filename”, “mode”);

Here “pointer” is a pointer variable, “fopen” is a keyword, “filename” is the name of the
file, and mode is the Mode of accessing the file.

File Opening Modes:

The mode argument specifies the type of operation you will be performing. In C commands,
you also enclose the mode arguments in quotation marks.

1
CHAPTER # 14: DATA FILES CLASS: XII

It can be:

Mode Meaning
“r” Open a text file for reading
“w” Create a text file for writing
“a” Append (add at end) to a text file
“r+” Open a text file for read/write
“w+” Create a text file for read/write
“a+” Append or create a text file for read/write
"r":
Opens a file for reading. The file must exist.
For example, if your program will be reading from the file, instead of writing a to it, use this
syntax:
FILE *fptr;
fptr = fopen(“myfile.txt”, “r”);

"w":
Creates an empty file for writing. If a file with the same name already exists, its content is
erased and the file is considered as a new empty file.
For example, to create a file called myfile.txt in the current directory for writing, you would
use:
FILE *fptr;
fptr = fopen(“myfile.txt”, “w”);

"a":
Appends to a file. Append mode causes a file to be created if it does not already exist. If it does
exist, the data you write on it will be added to the end of the file, without erasing its content.
For example, you want to append a file, use a command such as:
FILE *fptr;
fptr = fopen(“myfile.txt”, “a”);

2
CHAPTER # 14: DATA FILES CLASS: XII

Write a C program to Open a file using File opening Modes i.e. “a”, “w”, “r”.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
clrscr();
FILE *fp;
char ch, flag='y';
char name[30];

/* Creates an empty file for writing. If a file with the same name already exists, its content is
erased and the file is considered as a new empty file. */

fp=fopen("file.text","w");
if(fp==NULL)
printf("Error!\n");
else
{
while(flag!='n')
{
printf("Enter a name: ");
gets(name);
fputs(name,fp);
fputs("\n",fp);
printf("Enter more name? ");
flag = getche();
printf("\n\n");
}
}
fclose(fp);
getch();
}

3
CHAPTER # 14: DATA FILES CLASS: XII

// Opens a file for reading.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
clrscr();
FILE *fp;
char ch, flag='y';
char name[30];
fp=fopen("file.text","r");
if(fp==NULL)
printf("Error!\n");
else
while((ch=fgetc(fp))!=EOF)
printf("%c",ch);
fclose(fp);
getch();
}

/* If file exists, the data you write on it will be added to the end of the file.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
clrscr();
FILE *fp;
char ch, flag='y';
char name[30];
fp=fopen("file.text","a");
if(fp==NULL)
printf("Error!\n");
else
fputs("Hello world\nWelcome",fp);
fclose(fp);
getch();
}

4
CHAPTER # 14: DATA FILES CLASS: XII

Questions
1. Define data files.
2. Define the following file opening modes in C:
a. “r” b. “w” c. “a”

5
CHAPTER # 15: DATA MANAGEMENT SYSTEMS CLASS: XII

Chapter # 15: Data Management Systems


DATABASE:
A database is a collection of related files within an organization that can be retrieved and
manipulated to produce information. More specifically, a database is an electronic system that
allows data to be easily accessed, manipulated and updated.

BASIC TERMS OF DATABASE:


ENTITY:
Any object or event about which someone chooses to collect data is called an entity. An
entity may be a person, place, event, object, or concept in real world.
FIELD:
In a database table, a field is a data structure for a single piece of data. Fields are organized
into records, which contain all the information within the table relevant to a specific entity.

RECORD:
A record is a collection of related fields. An employee record would be a collection of fields
of one employee. These fields would include Employee Name, Employee pay, Tax-rate,
Employee ID, etc.

FILE:
A file is a collection of related records that are treated as a unit. For example, a collection of
all employee records for one company would be an employee file.

KEY FIELD:
A key field is a particular field chosen to uniquely identify a record so that it can easily
be retrieved and processed.

PRIMARY KEY:
A primary key is a column or a group of columns in a table that uniquely identifies the
rows in that table. For example, in the table Customer, Customer_No, which displays the ID
number assigned to different customers, is the primary key.

SECONDARY KEY:
A secondary key is an additional key, or alternate key, which can be used in addition to
the primary key to locate specific data.

FOREIGN KEY:
A Foreign Key creates a link between tables. It references the primary key in another
table and links.

1
CHAPTER # 15: DATA MANAGEMENT SYSTEMS CLASS: XII

DATABASE MANAGEMENT SYSTEM:


A DBMS is a software package that allows users to create, maintain, and manipulate a
database to produce useful information. The DBMS software represents the interface between
the user and the computer’s operating system and database. Oracle, MS Access and dBASE
are examples of Database Management Systems.

WHY IS DBMS NECESSARY FOR ANY BIG ORGANIZATION?

Database management systems are necessary for businesses and organizations because
they provide a highly efficient method for handling multiple types of data. Some of the data
that are easily managed with this type of system include: employee records, student
information, payroll, accounting, project management, inventory and library books. These
systems are built to be extremely versatile.

ADVANTAGES OF A DBMS:
The advantages of DBMS software are:

Reduction of Data Redundancy:


Data redundancy occurs in database systems which have a field that is repeated in two or more
tables. Database normalization prevents redundancy and makes the best possible usage of
storage.

Improvement of Data Integrity:


Since data are centralized, the data update at only one place reflects throughout the
system automatically.

Increase User Productivity:


Database Management Systems are fairly easy to use. The users can have answer of their
requests without having to report technical manipulations and computer professionals.

Increase Security:
Through the use of passwords, a student’s financial, medical, and grade information in
a university database is made available only to those who need to know.

COMPONENTS OF A DATABASE MANAGEMENT SYSTEM:


QUERY LANGUAGE:
A query language is an easy to use computer language for making queries to a database
and for retrieving information from a database. Typically, the query is in the form of sentence
or near English typed commands, using such basic words as SELECT, DELETE, or MODIFY.

2
CHAPTER # 15: DATA MANAGEMENT SYSTEMS CLASS: XII

DDL:
Data Definition Language (DDL) have facilities for describing the structure of fields,
records, files and program accessing rights. CREATE, ALTER, DROP, TRUNCUATE are the
commands of DDL.
DML:
Data Manipulation Language (DML) is used for accessing and updating data records and
files contained within the database.
INSERT, UPDATE, DELETE, MERGE, etc are the commands of DML.

SQL:
The SQL (Structured Query Language) contains all the features of both the data
definition language and the data Manipulation language. Also the American National Standards
Institute’s (ANSI) recommended language for relational database definition and manipulation
is SQL.

An Example of SQL query is as follow:


SELECT PRODUCT_ID, PRODUCT_NAME
FROM PRODUCT
WHERE PRICE < 1000

DATA DICTIONARY:
As data is entered, the data dictionary checks data to make sure that it follows the rules
defined during data definition, such as field name, field size, type of data. The data dictionary
may also help protect the security of the database by indicating who has the right to gain access
to it.

RESPONSIBILITIES OF A DATABASE ADMINISTRATOR:


A database administrator (DBA) is the information technician. A responsible to ensure
that data is available, protected from loss and corruption, and easily accessible as needed.

Below are some of the chief responsibilities that make up the day-to-day work of a DBA.
 Software installation and Maintenance
 Data Extraction, Transformation, and Loading
 Database Backup and Recovery
 Security
 Performance Monitoring

THE BASIC DATABASE MODELS:


A database model simply a model of the various ways in which the data within a database
may be structured. All the database systems are characterized by the way they structure,
organize, and manipulate data items and by the relationship among the items.

3
CHAPTER # 15: DATA MANAGEMENT SYSTEMS CLASS: XII

Three most popular models of database are:


1. Hierarchical database model
2. Network database model
3. Relational database model

Hierarchical Database Model:

In the hierarchical database model, data is organized like a family tree, with lower-level
records to higher-level records. A lower-level record is called a child, and a higher level record
is called a parent. The parent record at the top of the database is called the root record.

The Hierarchical Model

Network Database Model:


A Network Database model is similar to a hierarchical DBMS, but each child record
can have more than one parent record. The network database terms “member” and “owner” to
indicate this relationship. A record can be a member of more than one owner. Any record can
be related to any other data element. This database model is used to map many-to-many data
relationships.

The Network Model

4
CHAPTER # 15: DATA MANAGEMENT SYSTEMS CLASS: XII

Relational Database Model:


The relational database relates, or connects, data in different files through the use of a
key field, or common data element. Relational databases allow you to manipulate or control
more than one file at one time. It organizes data into tables called relations in mathematical
terms. Relations are subdivided into rows and columns. The rows represent data records, and
the columns represents fields within those records.

PARTS TABLE
Part Cost SHIPMENTS TABLE
Name Part Supplier
Number (Rs.) Quantity
123 ½ inch screw 5 Number Number
234 Circuit Board 25 123 1 2000
345 Coiled cord 45 234 2 4000
456 Keyboard Casing 200 345 3 2300
567 Key Set 95 456 4 5400
567 5 2100

SUPPLIERS TABLE
Suppliers
Name Address Phone
Number
34 Ground
1 Pak Hardware 5872843
Street
2 Computer Company 3854732
21 Mall Road
3 Badar Hardware 4857839
14 Kashif Lane
4 Dataline Wiring 6758987
45 Silver
5 Electro Electronics 3547678
76 Green Street

The Relational Model

RDBMS:
RDBMS stands for Relational Database Management System is a collection of programs
and capabilities that enable IT teams and others to create, update, administer and otherwise
interact with a relational database. RDBMS stores data in the form of tables, with most
commercial relational database management systems using Structured Query Language (SQL)
to access the database.

ADVANTAGES OF RDBMS:
Following are the benefits or advantages of RDBMS:

5
CHAPTER # 15: DATA MANAGEMENT SYSTEMS CLASS: XII

 It is easy to use.
 The data manipulation can be done.
 It reduces redundancy and replication of the data.
 It offers better data integrity.
 It provides better physical data independence.
 It offers logical database independence i.e. data can be viewed in different ways by the
different users.
 It provides multiple interfaces.
 It provides better backup and recovery procedures.

Difference between DBMS and RDBMS:

DBMS RDBMS
1. RDBMS applications store data in
1. DBMS applications store data as file
tabular form.
2. DBMS does not support distributed
2. RDBMS supports distributed database.
database.
3. DBMS is meant to be small organization 3. RDBMS is designed to handle large
and deal with small data. amount of data.
4. It supports single user. 4. It supports multiple users.

5. Examples of DBMS are file systems, 5. examples of RDBMS are mysql, sql
xml, etc. server, oracle, etc.

Questions:
1. What is database? (Short)
2. What is Entity, Field, Record, and file? (Short)
3. What is Key field, Primary Key, Secondary Key, and Foreign Key? (Short)
4. What is Database Management System (DBMS)? Describe it with examples. (Short)
5. Why is DBMS necessary for any big organization? (Short)
6. Describe advantages of DBMS. (Short)
7. What is query language? (Short)
8. What is DDL and DML? (Short)
9. What is Data Dictionary? (Short)
10. What are the components of DBMS? Describe them all. (Long)
11. What are the responsibilities of DBA?
12. What is database model? Name the various database models. (Short)
13. Describe Hierarchical Database Model with diagram? (Long)
14. Describe Network Database Model with diagram? (Long)
15. Describe Relational Database Model with diagram? (Long)

6
CHAPTER # 15: DATA MANAGEMENT SYSTEMS CLASS: XII

16. What is RDBMS? (Short)


17. Write the Advantages of RDBMS. (Short)
18. Write the differences between DBMS and RDBMS. (Short)

Multiple Choice Questions (MCQ’s)


1. This database model organizes data in a tree structure:
a. Hierarchical b. Relational c. Network d. Object Oriented model
2. A row in a table is also called a:
a. Field b. Tuple c. Entity d. Attribute

3. The specialized software necessary to create and process the database and modified as
needed is called:
a. Compiler b. Windows XP c. DBMS d. Interpreter

4. This is called the collection of related fields:


a. Record b. Table c. Entity d. Attribute

5. Key field must contain:


a. Filtered values b. Default values c. Unique values d. Duplicate values

6. A type of database which stores information in the form of table:


a. Hierarchical b. Network c. Relational d. Tree

7. A field in a DBMS is sometimes called a/an:


a. File b. Attribute c. Record d. Database

8. A foreign key:
a. Has nothing to do with primary key
b. has different values than the primary key
c. is found in a tables that do not have a primary key
d. is related to the primary key of a different table

8. The columns in a database table are called a:


a. Rows b. Records c. Fields d. Entities

7
CHAPTER # 16: BASICS OF MS ACCESSS CLASS: XII

Chapter # 16: Basics of MS Access


MS-ACCESS:
MS-Access is a powerful Windows-based relational database management system
(RDBMS) for organizing and storing large volumes of data in a relatively small space so that
you can find data more effectively.

MAIN OBJECTS OF DATABASE OR MS-ACCESS:


Each database object belongs to a category of objects known as a class. Microsoft has
following seven classes of database objects:
1.Table: An organized collection of rows and columns used to store field data.
2. Query: An object that is used to view, change, or organize data.
3. Form: A graphical object that displays data from table or a query in an easy-to-use format.
4. Report: An object used to present data in a printed format.
5. Page: Data Access pages are HTML files designed in Access and formatted to display in a
Web browser.
6. Macro: A set of one or more actions that are used to automate common tasks such as opening
a form or printing a report.
7. Module: A collection of Visual Basic for Applications programming components that are
stored together as a unit.

ACCESS DATA TYPES:


A data type is a characteristic of how data is stored in a database. Microsoft Access
summarizes the ten data types you may use for table data.

1. Text: Any combination of alphabetic and numeric characters such as names,


addresses, and phone numbers. The text data type holds maximum 255
characters.
2. Memo: It is used for long text entries exceeding 255 characters. Holds up 64
kilobytes of data in a random format.
3. Number: It includes numeric values such as inventory quantity or the number of
items ordered. It can be used for calculations.
4. Date/ Time: It includes Date and time values from the years 100 to 9999.
5. Currency: Currency values and numeric data used in mathematical calculations
involving data with one to four decimal places
6. Auto A unique and sequential number is created as records are added to the
Number: table. AutoNumber data cannot be changed, edited, or deleted.
Single character data in a Yes/ No (Boolean) Format. This data type
7. Yes/ No: displays a checkbox.

1
CHAPTER # 16: BASICS OF MS ACCESSS CLASS: XII

8. OLE object: Embedded or linked objects such as Microsoft Excel spreadsheet, a


MS-Word document, graphics, or sounds.
9. Hyperlink: It is a combination of texts and numbers used as a hyperlink address.
This type is used to link to other Web pages or other documents.
10. Lookup A field that allows you to choose a value from another table or from a
Wizard: list of values

Questions
1. What is MS-Access? (Short)
2. What are the main objects of database or MS-Access? (Short)
3. What are the main objects of database or MS-Access? Describe them. (Long)
4. What are the Data types in MS-Access? Name them. (Short)
5. Describe the Data types in MS-Access. (Long)

2
CHAPTER # 16: BASICS OF MS ACCESSS CLASS: XII

Multiple Choice Questions (MCQ’s)

1. Which Access object is considered as primary?


a. Table b. Query c. Form d. Report
2. The database tool is used to display and print your data in an organized manner:
a. Table b. Query c. Form d. Report
3. This view is used to enter data into a table:
a. Table Design View b. Datasheet View
c. Database Location View d. Database Design View

4. Access supports _______ data types.


a. Four b. Ten c. Seven d. Five

5. In Datasheet View, each record represents a:


a. Query b. Form c. Record d. Field

6. Microsoft Access is a ___________ database:


a. Hierarchical b. Network c. Relational d. Tree

7. Which of the following data types allows you to specify a field size?
a. Text b. number c. Date/ Time d. Currency

3
Chapter # 17: Advanced MS Access 2000
Relationship:
A Relationship is a link that is created and maintained between two tables that enables
data to be accessed from both the tables simultaneously, and is technically called a join.

Types of Relationship:
Access recognize three kinds of relationships which are as follow
1. One-to-one
2. One-to-many
3. Many-to-Many

One-to-one:
Each record in table A can have only one matching record in table B. and each record
in a table B can have only one matching record in table A.

One-to-many:
A one-to-many relationship is the most common type of relationship. A record in table
A can have many matching in table B, but record in table B has only one matching record in
table A.

Many-to-Many:
In a many-to-many relationship, a record in a table A can have many matching records
in table B, and a record in table B can have many matching records in table A.

WHY DO WE USE TABLE, FORM, AND REPORT IN MS-ACCESS?


The most basic, fundamental task of a database is to store data for easy retrieval and
management, and its tables that do this work. With a form, you can view and edit the data,
display it nicely, sort it, add to it, delete it and so on. Forms let you work with your data. Once
you have edited, updated, and completed your data, you can print your data on a paper through
the reports in a prescribed form.

Questions
1. What is Relationship in a database? What are the types of relationship? Name them.
(Short)
2. Describe the types of relationship in database. (Long)
3. Why do we use Table, Form, and Report in MS-Access?

MPA STUDY PACK COMPUTER CXII 1


Multiple Choice Questions (MCQ’s)

1. You can easily create relationships between tables by using:


a. Datasheet View b. Table design View
c. The lower pan of the design view d. The Relationship Window
2. This is used to view, change, and analyze data in different ways:
a. Form b. Query c. Table d. Report
3. A ___________ relationship is the most common kind of relationship among tables:
a. One-to-one b. One-to-many
c. Many-to-many d. None of them
4. The “many” side of a one-to-many relationship is represented with:
a. a line b. the number 1 c. the word many d. the infinity symbol

MPA STUDY PACK COMPUTER CXII 2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy