0% found this document useful (0 votes)
14 views18 pages

Computer Applications Notes-1

Unit III covers computer languages, their generations, translators, algorithms, pseudo-code, and flowcharts. It explains the evolution of programming languages from low-level to high-level, the role of translators like compilers and interpreters, and the importance of algorithms in problem-solving. Additionally, it introduces pseudo-code and flowcharts as tools for representing algorithms visually.

Uploaded by

ah6947145
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views18 pages

Computer Applications Notes-1

Unit III covers computer languages, their generations, translators, algorithms, pseudo-code, and flowcharts. It explains the evolution of programming languages from low-level to high-level, the role of translators like compilers and interpreters, and the importance of algorithms in problem-solving. Additionally, it introduces pseudo-code and flowcharts as tools for representing algorithms visually.

Uploaded by

ah6947145
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Unit III: Computer Languages,

Translators, and Programming


Fundamentals
1. Computer Languages 💻
Definition / Concept
Computer Language ek medium hai jisse hum computer ko instructions de sakte hain.
Simple words mein, yeh computer se baat karne ka tareeka hai. Computer sirf binary code
(0s aur 1s) samajhta hai, lekin hum log uski language mein program likh nahi sakte, isliye hum
aisi languages use karte hain jinhe computer ke liye translate kiya jaa sake.

Detailed Explanation in Hinglish


Dekho, jaise hum insaan ek doosre se Hindi, English, ya koi aur bhasha mein baat karte hain,
waise hi programmers computer ko kaam batane ke liye programming languages use karte
hain. Har language ka apna syntax (grammar) aur rules hote hain. Computer languages ko
teen levels mein divide kiya jaa sakta hai:
1.​ Low-Level Language (LLL): Yeh language computer hardware ke bahut nazdeek hoti
hai. Isko computer jaldi samajh leta hai, but insaan ke liye isme code likhna mushkil hota
hai.
○​ Examples: Machine Language aur Assembly Language.
2.​ Middle-Level Language (MLL): Yeh Low-Level aur High-Level ke beech ki language hai.
Yeh hardware ko bhi access de sakti hai aur insaan ke liye thodi aasan bhi hoti hai.
○​ Example: C Language (jise aksar High-Level ki tarah bhi dekha jaata hai, lekin
usme Low-Level features bhi hote hain).
3.​ High-Level Language (HLL): Yeh insaan ki bhasha (English words, mathematical
symbols) ke zyada kareeb hoti hai. Isme code likhna aasan hota hai, par computer ko
samajhne mein zyada translation ki zaroorat padti hai.
○​ Examples: C++, Java, Python, C#.

Real-life or Practical Use


Ek Civil Engineer jo Structural Analysis software (jaise SAP2000, STAAD Pro) ya AutoCAD
use karta hai, woh bhi indirectly inhi languages se bane software use kar raha hai.
Programming languages se hi yeh complex software bante hain.

Important Short Points for Revision


●​ Computer Language \rightarrow Computer se instructions dene ka tareeka.
●​ LLL \rightarrow Machine ke nazdeek, difficult for humans (Machine, Assembly).
●​ HLL \rightarrow Humans ke nazdeek, easy for humans, needs translator (C++, Java,
Python).
2. Generation of Languages (1st to 5th) ⏳
Generation Name Key Feature Example
1st GL Machine Language Binary Code (0s & \text{0101 1100 0010}
1s). No translator (Direct CPU command)
needed.
2nd GL Assembly Language Uses Mnemonics \text{MOV A, B} (Move
(short codes like B's content to A)
\text{ADD, SUB,
MOV}). Needs an
Assembler.
3rd GL High-Level Language Procedural / C, C++, FORTRAN,
Structured. COBOL
English-like statements.
Easier to learn.
4th GL Very High-Level Non-Procedural. SQL, MATLAB
Language Focus on what to do,
not how to do it. Used
for database and
reports.
5th GL Artificial Intelligence Problem-solving aur Prolog, LISP
Languages AI applications ke liye.
Computer khud
decision leta hai.
Detailed Explanation in Hinglish
Jaise mobile phone ki generations (2G, 3G, 4G, 5G) badli hain, waise hi computer languages
bhi time ke saath develop hui hain.
●​ 1st Gen: Sabse pehle, computer ko direct 0 aur 1 mein bataya jaata tha. Socho, ek
chhota sa program likhne mein kitni mushkil hoti hogi!
●​ 2nd Gen: Fir Assembly Language aayi. Isme \text{ADD} (add), \text{SUB} (subtract)
jaise mnemonics use hote the. Thoda aasan hua, but abhi bhi hardware specific thi.
●​ 3rd Gen (HLLs): Yeh revolutionary thi! Isse C aur Java jaisi languages aayi. Ab
programmer ko hardware ki chinta nahi karni padti thi. Civil Engineering software
zyada tar is generation mein hi likhe jaate hain.
●​ 4th Gen: Agar tumhe database se data nikalna hai ya report banani hai, toh 4GL use
hoti hai. Jaise \text{SQL} (Structured Query Language), jahan bas hum result maangte
hain, steps nahi batate.
●​ 5th Gen: Yeh latest hai. Iska main focus AI (Artificial Intelligence), Robotics, aur

🔄
Natural Language Processing pe hai. Future mein iska use bahut badhega.

3. Translators (Assembler, Interpreter, Compiler)


Definition / Concept
Translator ek special software hai jo ek computer language mein likhe gaye program (source
code) ko doosri language (jaise Machine Code) mein badalta hai, taaki computer use samajh
kar execute kar sake.

Detailed Explanation in Hinglish


Computer sirf Machine Language (0s and 1s) samajhta hai, aur hum code likhte hain
High-Level Language mein. Toh translation toh zaroori hai. Yahi kaam Translators karte hain.
Translator Function Working Style Example Language
Assembler Assembly Language Poora program ek baar Assembly Language
ko Machine Code mein mein translate karta
badalta hai. hai.
Compiler High-Level Language Poora Source Code ek C, C++, Java (partially)
ko Machine Code mein saath padhta hai,
badalta hai. Errors ki list nikalta hai,
aur agar koi error na
ho, toh poora
executable file (.exe)
bana deta hai.
Interpreter High-Level Language Line-by-line translation Python, PHP,
ko Machine Code mein aur execution karta hai. JavaScript
badalta hai. Agar ek line mein error
ho, toh wahin ruk jaata
hai.
●​ Compiler tez hota hai kyunki woh ek hi baar mein poora program machine code mein
change kar deta hai.
●​ Interpreter debugging (errors dhoondna) ke liye achha hota hai kyunki woh jahan error
aati hai, wahin ruk jaata hai.

Real-life or Practical Use


Jab tum C language mein apna program likh kar use run karte ho, toh Compiler hi us C Code
ko tumhare computer ke samajhne waale machine code mein convert karta hai, tabhi tumhara
program run ho pata hai.

Important Short Points for Revision


●​ Assembler \rightarrow Assembly \rightarrow Machine.
●​ Compiler \rightarrow HLL \rightarrow Machine Code (all at once), creates \text{.exe}.

📜
●​ Interpreter \rightarrow HLL \rightarrow Machine Code (line-by-line), stops at first error.

4. Algorithm
Definition / Concept
Algorithm kisi bhi problem ko solve karne ke steps ka ek well-defined, step-by-step
procedure hota hai. Yeh computer code likhne se pehle banaya jaata hai.

Detailed Explanation in Hinglish


Socho, agar tumhe college canteen se do plate Samosa laane hain. Tum uska ek plan
banaoge, right?
1.​ Start
2.​ Canteen jaao.
3.​ Paisa nikaalo.
4.​ Order do: "Do plate samosa chahiye."
5.​ Payment karo.
6.​ Samosa lo.
7.​ Wapas classroom aao.
8.​ End Yahi step-by-step plan Algorithm hai. Computer programming mein bhi, code likhne
se pehle hum problem ko solve karne ka exact logic Algorithm mein likhte hain.

Example in Simple Logic (Algorithm to Calculate Area of a Circle)


1.​ START
2.​ Input (Read) the radius (r) of the circle.
3.​ Set the value of \pi (pi) as 3.14159.
4.​ Calculate the area using the formula: \text{Area} = \pi \times r \times r.
5.​ Output (Print) the calculated Area.
6.​ STOP

Real-life or Practical Use


Civil Engineering mein, koi bhi complex calculation (jaise Beam design ke bending moment
ko calculate karna) ho, toh uske liye sabse pehle uske mathematical steps ka Algorithm
banana padta hai.

Important Short Points for Revision


●​ Algorithm \rightarrow Problem solve karne ka step-by-step procedure.
●​ Yeh code likhne se pehle ka plan hai.

📝
●​ Should be unambiguous (clear) and finite (khatam hone waala).

5. Pseudo-code
Meaning and Example
Pseudo-code (Pseudo ka matlab 'fake' ya 'nakli') ek tarah se aadh-adhura (half-complete)
code hota hai. Yeh na toh poori tarah English hai, aur na hi poori tarah koi programming
language (jaise C). Yeh Algorithm ko thoda programming style mein likhne ka tareeka hai,
jisme hum English words aur programming keywords ka use karte hain.
●​ Why use it? \rightarrow Isse programming logic aur bhi clear ho jaata hai, aur ise koi
bhi programmer aasani se samajh sakta hai.
Example (Pseudo-code for Area of a Circle)
FUNCTION Calculate_Circle_Area​
// Define PI​
PI = 3.14159​

// Get radius from user​
INPUT radius_r​

// Check if radius is valid​
IF radius_r IS LESS THAN 0 THEN​
PRINT "Invalid Radius! Cannot calculate area."​
ELSE​
// Calculate the area​
Area = PI * radius_r * radius_r​

// Display the result​
DISPLAY Area​
ENDIF​
END FUNCTION​

Important Short Points for Revision


●​ Pseudo-code \rightarrow \text{Algorithm} + \text{Programming Style}.
●​ No specific syntax (koi fix rules nahi).

➡️
●​ Helps to transition from \text{Algorithm} \rightarrow \text{Code}.

6. Flowcharts
Definition / Concept
Flowchart ek pictorial (diagrammatic) representation hai kisi bhi Algorithm ka. Isme
standard symbols ka use karke steps aur unke flow (direction) ko dikhaya jaata hai.

Rules & Symbols with Example Diagram


Flowchart mein har type ke step ke liye ek standard symbol hota hai.
Symbol Name Use
\text{Oval} Terminal START aur END ko darshata
hai.
\text{Parallelogram} Input / Output Data lena (\text{Input}) ya
dikhana (\text{Output})
\text{Rectangle} Process Calculations ya koi bhi action
karna.
\text{Diamond} Decision Condition check karna (jaise
Symbol Name Use
\text{YES}/\text{NO} ya
\text{True}/\text{False}).
\text{Arrows} Flow Lines Ek step se doosre step tak
execution ka direction
batana.
Example Diagram (Flowchart to check if a number is positive or
negative)
1.​ Start/End: Oval
2.​ Input \text{N}: Parallelogram
3.​ Is \text{N} > 0? : Diamond (Decision)
4.​ If Yes: Process (Print Positive)
5.​ If No: Process (Print Negative)
6.​ Connect all with Arrows (Flow Lines)

Important Short Points for Revision


●​ Flowchart \rightarrow Algorithm ka pictorial representation.
●​ Symbols use hote hain.

💡
●​ Flow Lines \rightarrow Direction of execution.

Unit IV: Introduction to C Language


and Programming Constructs
1. Introduction to ‘C’ Language 🧑‍💻
Importance and Features
C Language ko Dennis Ritchie ne 1972 mein Bell Labs mein develop kiya tha. Isko "Mother of
all Languages" bhi kaha jaata hai, kyunki bahut saari modern languages (jaise C++, Java, C#)
iske syntax aur concepts pe based hain.

Importance

●​ Base Language: Yeh OS (Operating Systems), Compilers, aur Database Systems ko


develop karne ke liye use hui hai.
●​ Efficient: Yeh fast aur efficient code generate karti hai.
●​ Structural: Yeh Structured Programming ko support karti hai, jisse complex programs
ko small parts mein divide karna aasan ho jaata hai.
●​ System Programming: Hardware ke nazdeek hone ki wajah se, yeh drivers aur
embedded systems mein use hoti hai, jo Civil Engineering ke IOT (Internet of Things)
based monitoring systems mein kaam aata hai.
Features

1.​ Mid-Level Language: HLL ke features ke saath LLL ke features (hardware access) bhi
deta hai.
2.​ Portability: C programs ko aasani se ek machine se doosri machine par run kiya ja
sakta hai (thode se changes ke saath).

🧱
3.​ Rich Library: Iske paas bahut saare built-in functions ki library hai.

2. Basic Structure of a C Program


Detailed Explanation with Sample Code
Har C program ek standard structure follow karta hai. Isko samajhna bahut zaroori hai.
1.​ Documentation Section: Comments (jo program ka naam, author, date batate hain)
2.​ Link Section: Header files ko link karna (\text{\#include} \dots)
3.​ Definition Section: Global variables/constants ko define karna.
4.​ Global Declaration Section: Global variables ko declare karna.
5.​ main() Function Section: Har C program ka execution yahin se shuru hota hai.
6.​ Sub-Program Section: User-defined functions (agar koi ho toh).

Sample Code
#include <stdio.h> // Link Section: Standard Input/Output library
ko include kiya​

// Global Declaration Section (Optional): Agar koi variable sab
functions ke liye chahiye​
// int global_var = 10; ​

int main() // main() Function Section: Program ka starting
point​
{​
/* Documentation Section: Yeh ek multi-line comment hai */​
// Yeh single-line comment hai​

// Process: Screen par "Hello, World!" print karna​
printf("Hello, DCA-305 Students!\n"); ​

return 0; // 0 return karna matlab 'Success' ya
'Program theek se chala'​
} // main function ka end​

Output of code:
Hello, DCA-305 Students!​
Important Short Points for Revision
●​ \text{\#include} \rightarrow Header files include karta hai.
●​ \text{main()} \rightarrow Execution start hota hai.
●​ Comments (\text{/* } \dots \text{ */}) aur (\text{// } \dots) \rightarrow Compiler ignore karta

🔠
hai.

3. Constants, Variables, and Data Types


Detailed Explanation with Declaration Examples
1. Variables

Variable computer ki memory mein ek named storage location hai, jahan hum data store
karte hain. Iski value change ho sakti hai program ke execution ke dauraan.
●​ Civil Example: Ek variable \text{beam\_length} mein hum beam ki length store kar sakte
hain.
Data Type Memory Size (Approx.) Example Value Declaration Example
int 2 or 4 bytes 42, -100 \text{int student\_id;}
float 4 bytes 12.34, 0.0 \text{float area\_sqm;}
char 1 byte 'A', 'z' \text{char grade;}
2. Constants

Constant ek aisi value hai jo program ke execution ke dauraan badalti nahi hai.
●​ Example: \text{PI} ki value (3.14) ya Gravity (9.81 \text{ m/s}^2) hamesha constant rehti
hai.
<!-- end list -->
#include <stdio.h>​

int main() {​
// Variable Declaration​
int students_in_class = 60; // int (Integer) type ka variable​
float weight_of_steel = 5600.75; // float (Decimal) type ka
variable​
char initial_letter = 'R'; // char (Character) type ka variable​

// Constant Declaration using 'const' keyword​
const float PI = 3.14159; ​

printf("Students: %d\n", students_in_class);​
printf("Steel Weight: %.2f kg\n", weight_of_steel);​
printf("PI value: %.5f\n", PI);​

return 0;​
}​
Important Short Points for Revision
●​ Variable \rightarrow Value can change.
●​ Constant \rightarrow Value cannot change (\text{const} keyword).

🔢
●​ int, float, char \rightarrow Most common Data Types.

4. Operators and Expressions


Definition / Concept
Operator ek symbol hai jo compiler ko mathematical ya logical manipulation perform karne
ke liye bolta hai. Expression operators aur operands (variables/constants) ka combination hota
hai.

Examples of Operators
Type Operator Meaning C Example Result (if
\text{A}=10,
\text{B}=3)
Arithmetic \text{+, -, *, /, \%} \text{Add, Sub, \text{A \% B} 1
Mul, Div,
Remainder}
Relational \text{<, >, <=, >=, \text{Less than, \text{A > B} \text{True (1)}
==, !=} Greater than,
Equal to}
Logical \text{\&\&, \|\|, \text{AND, OR, \text{(A > 5) \&\& \text{True (1)}
NOT} (B < 10)}
Assignment \text{=, +=, -=} \text{Assign, \text{A += 5} \text{A} becomes
Compound 15
assignment}
#include <stdio.h>​

int main() {​
int x = 20, y = 3;​
int sum, remainder;​
int is_equal;​

// Arithmetic Expression Example​
sum = x + y; // sum = 23​
remainder = x % y; // remainder = 20 % 3 = 2​

// Relational Expression Example (Result 1 for true, 0 for false)​
is_equal = (x == y); // is_equal = 0 (False)​

// Logical Expression Example (AND: dono true hone par hi true)​
if (x > 10 && y < 5) {​
printf("Condition is True!\n"); // Yeh line execute hogi​
}​

printf("Sum: %d\n", sum);​
printf("Remainder: %d\n", remainder);​

return 0;​
}​

Important Short Points for Revision


●​ \text{==} \rightarrow Equality check (do barabar hai ya nahi).
●​ \text{=} \rightarrow Assignment (value assign karna).

📤
●​ \text{\&\&} \rightarrow Logical AND (dono condition true).

5. Managing Input and Output Operators


Detailed Explanation with Examples
Input/Output (I/O) functions user se data lene (Input) aur screen par data dikhane (Output) ke
liye use hote hain. Yeh functions \text{<stdio.h>} header file mein available hote hain.
Function Type Use
\text{printf()} Output Screen par data print karta hai.
\text{scanf()} Input User se keyboard ke through
data leta hai.
C Code Example
#include <stdio.h>​

int main() {​
int slab_thickness;​
float concrete_grade_strength;​

// Output: User ko batana ki kya input karna hai​
printf("Slab ki thickness (mm me) daalo: ");​

// Input: User se integer value lena aur slab_thickness variable
me store karna​
// %d -> format specifier for integer​
// & -> address of operator (value ko kahan store karna hai, uski
location)​
scanf("%d", &slab_thickness); ​

printf("Concrete ki compressive strength (MPa me) daalo: ");​

// Input: User se float value lena​
// %f -> format specifier for float​
scanf("%f", &concrete_grade_strength); ​

// Output: Stored data ko screen par dikhana​
printf("\n--- Input Summary ---\n");​
printf("Slab Thickness: %d mm\n", slab_thickness);​
printf("Concrete Strength: %.2f MPa\n", concrete_grade_strength);​

return 0;​
}​

Example Output:
Slab ki thickness (mm me) daalo: 150​
Concrete ki compressive strength (MPa me) daalo: 25.45​

--- Input Summary ---​
Slab Thickness: 150 mm​
Concrete Strength: 25.45 MPa​

Important Short Points for Revision


●​ \text{printf()} \rightarrow Output ke liye.
●​ \text{scanf()} \rightarrow Input ke liye.
●​ \text{\%d, \%f, \%c} \rightarrow Format Specifiers (data type batane ke liye).

🚦
●​ \text{\&} \rightarrow \text{scanf()} mein variable ka address dena zaroori hai.

6. Control Statements (Decision Making)


Control Statements program ke execution flow ko control karte hain.

6.1. if, if-else, nested if, else-if ladder


Yeh statements conditions ke basis par decision lene ke liye use hote hain.
Statement Use Logic
if Ek condition check karta hai. \text{If condition is True, do
Agar \text{True} hai, toh block this.}
run hota hai.
if-else Ek condition check karta hai. \text{If True, do A, else do B.}
Agar \text{True}, toh \text{if}
block, \text{False} toh
\text{else} block.
else-if ladder Multiple conditions ko \text{Check C1. If True, do A.
sequentially check karta hai. Else, check C2. If True, do B.
Else, do Z.}
Nested if Ek \text{if} block ke andar \text{If C1 is True, then check
doosra \text{if} statement. C2.}
C Code Example (else-if ladder for Grading)

Real-life use: Building material ki quality check karna.


#include <stdio.h>​

int main() {​
int marks = 85; ​

printf("Student ka Marks: %d\n", marks);​

// else-if ladder: Marks ke hisaab se Grade assign karna​
if (marks >= 90) {​
printf("Grade: A+ (Excellent Work)\n");​
} ​
else if (marks >= 80) { // Agar pehla if False hua, toh yeh check
hoga​
printf("Grade: A (Very Good)\n");​
} ​
else if (marks >= 60) {​
printf("Grade: B (Good)\n");​
} ​
else { // Agar upar ki saari conditions False hui, toh yeh default
execute hoga​
printf("Grade: C (Needs Improvement)\n");​
}​

return 0;​
}​

Output:
Student ka Marks: 85​
Grade: A (Very Good)​

6.2. goto statement


goto statement program ke control ko jump kara kar doosri location (jo \text{label} se define
ki jaati hai) par le jaata hai.
●​ Note: \text{goto} ka use avoid karna chahiye kyunki yeh program ke logic ko
complicated bana deta hai, jisse debugging mushkil ho jaati hai. Structured
Programming mein ise bad mana jaata hai.

C Code Example

#include <stdio.h>​

int main() {​
int i = 1;​

check_i: // Yeh ek 'label' hai​

if (i <= 3) {​
printf("i is: %d\n", i);​
i++;​
goto check_i; // Control ko vapas 'check_i' label par bhej
diya​
}​

// Iske baad 'i is: 4' print nahi hoga​

return 0;​
}​

Output:
i is: 1​
i is: 2​
i is: 3​

7. Looping Statements (Iteration) 🔁


Looping ka matlab hai ki kisi block of code ko baar-baar repeat karna jab tak ek condition
false na ho jaaye.

for, while, do-while (with C code examples)


Loop Type Condition Check Use Case
for Beginning mein check karta Jab humein pata ho ki loop
hai. kitni baar chalana hai (Fixed
number of iterations).
while Beginning mein check karta Jab tak koi condition \text{True}
hai. rahe (Unknown number of
iterations).
do-while End mein check karta hai. Jab humein at least ek baar
loop chalana ho.
C Code Example (for loop to calculate sum of numbers)

Real-life use: Ek building mein jitne bhi \text{Rebars} hain, un sab ka total \text{Weight}
calculate karna.
#include <stdio.h>​

int main() {​
int i, sum = 0;​
int n = 5; // Total numbers ka count​

// for loop: i=1 se start karo, jab tak i<=n (5) hai, tab tak
chalo, aur har bar i ko 1 se badhao​
for (i = 1; i <= n; i++) ​
{​
sum = sum + i; // sum me i ki value add karte jao​
// Pehle: sum = 0+1=1, Doosre: sum = 1+2=3, ...​
}​

printf("Sum of first %d numbers is: %d\n", n, sum); ​

return 0;​
}​

Output:
Sum of first 5 numbers is: 15​

C Code Example (while loop)

#include <stdio.h>​

int main() {​
int count = 1;​
// Condition: Jab tak count 3 se chota ya barabar hai, tab tak
chalta rahega​
while (count <= 3) { ​
printf("Loop run: %d\n", count);​
count++; // Increment karna zaroori hai, varna infinite loop
ho jayega​
}​
return 0;​
}​

Output:
Loop run: 1​
Loop run: 2​
Loop run: 3​

8. switch decision-making statement 🎛️


Definition / Concept
switch statement ek \text{else-if ladder} ka alternative hai. Jab humein ek hi expression ki
value ko multiple constant values ke saath compare karna ho, toh \text{switch} use karte hain.
Menu-Driven Example
Real-life use: Calculator ya CAD software mein koi tool select karna.
#include <stdio.h>​

int main() {​
int choice;​

printf("--- Civil Engineer Tools ---\n");​
printf("1. Calculate Area\n");​
printf("2. Calculate Volume\n");​
printf("3. Exit\n");​
printf("Apni Choice daalo (1, 2, or 3): ");​
scanf("%d", &choice);​

// switch (expression): choice ki value check hogi​
switch (choice) {​
case 1: // Agar choice 1 hai​
printf("Area Calculation Tool Selected.\n");​
// yahan area calculation ka code aayega​
break; // break se switch block se bahar nikal jaate hain​

case 2: // Agar choice 2 hai​
printf("Volume Calculation Tool Selected.\n");​
// yahan volume calculation ka code aayega​
break;​

case 3:​
printf("Exiting Tool.\n");​
break;​

default: // Agar choice 1, 2, ya 3 nahi hai​
printf("Invalid Choice! Please select 1, 2, or 3.\n");​
}​

return 0;​
}​

Example Output (if user inputs 2):


--- Civil Engineer Tools ---​
1. Calculate Area​
2. Calculate Volume​
3. Exit​
Apni Choice daalo (1, 2, or 3): 2​
Volume Calculation Tool Selected.​
Important Short Points for Revision
●​ switch \rightarrow Ek \text{expression} ko multiple constant values se compare karta
hai.
●​ case \rightarrow Har value ke liye ek \text{case} hota hai.
●​ break \rightarrow Zaroori hai, varna execution aage ke cases mein bhi chala jaayega
(fall-through).

📦
●​ default \rightarrow Agar koi \text{case} match na ho, toh yeh run hota hai.

9. Arrays
Definition / Concept
Array ek hi data type ke similar data items ka collection hai, jo memory mein ek saath
(contiguously) store hota hai. Har item ko uske index (position number, jo 0 se start hota hai)
se access kiya jaata hai.

Detailed Explanation with Example Code


Socho, agar tumhe 60 students ke marks store karne hain. Toh kya tum 60 alag-alag variables
banaoge (\text{mark1, mark2, } \dots)? Nahi! Hum ek Array banayenge.
●​ Syntax: \text{data\_type \ array\_name[size];}

C Code Example (Single-Dimensional Array)

Real-life use: Ek particular beam ke liye sare stirrups ki spacing store karna.
#include <stdio.h>​

int main() {​
// Array declaration: 5 integer values store kar sakte hain​
int student_marks[5]; ​
int i;​
int total_marks = 0;​

// Array Initialization (Values assign karna)​
student_marks[0] = 75; // 1st element (Index 0)​
student_marks[1] = 88;​
student_marks[2] = 62;​
student_marks[3] = 90;​
student_marks[4] = 70; // 5th element (Index 4)​

printf("Marks of the 5 students:\n");​

// Loop use karke saare elements ko access karna​
for (i = 0; i < 5; i++) {​
printf("Student %d: %d\n", i + 1, student_marks[i]);​
total_marks = total_marks + student_marks[i];​
}​

printf("\nTotal Marks: %d\n", total_marks);​

return 0;​
}​

Output:
Marks of the 5 students:​
Student 1: 75​
Student 2: 88​
Student 3: 62​
Student 4: 90​
Student 5: 70​

Total Marks: 385​

Multi-Dimensional Array (Brief)


Yeh Array of Arrays hota hai, jaise Matrices. Civil Engineering mein yeh 2D ya 3D analysis
(jaise element stiffness matrices) mein use hota hai.
●​ Example: \text{int matrix[3][3];} (3 rows, 3 columns)

Important Short Points for Revision


●​ Array \rightarrow Collection of similar data types.
●​ Index \rightarrow Starts from 0.
●​ Single-D \rightarrow List (ek row).

⚙️
●​ Multi-D \rightarrow Table / Matrix.

10. Functions (User-Defined Functions)


Definition / Concept
Function ek self-contained block of code hota hai jo ek specific task perform karta hai. Jab
hum ek bade program ko chote-chote functions mein divide karte hain, toh program ko
samajhna, debug karna aur maintain karna aasan ho jaata hai.

User-Defined Functions: Declaration, Definition, Call


1.​ Declaration (Prototype): Compiler ko batana ki function kaisa dikhega (uska naam,
return type, aur parameters). Yeh \text{main()} se pehle aata hai.
2.​ Definition: Function ke andar ka code (actual logic) likhna.
3.​ Call: Function ko execute karne ke liye uska naam use karna.
C Code Example (Function to calculate a square)

Real-life use: Ek hi formula (jaise \text{Area of a Square}) ko program mein alag-alag jagah
use karna.
#include <stdio.h>​

// 1. Function Declaration (Prototype)​
float calculate_square_area(float side); ​

int main() {​
float room_side = 4.5;​
float footing_side = 1.2;​
float room_area, footing_area;​

// 3. Function Call: Value pass karna​
room_area = calculate_square_area(room_side);​
footing_area = calculate_square_area(footing_side);​

printf("Room Area (4.5m side): %.2f sq.m\n", room_area);​
printf("Footing Area (1.2m side): %.2f sq.m\n", footing_area);​

return 0;​
}​

// 2. Function Definition​
float calculate_square_area(float side) {​
float area = side * side; // Specific task perform karna​
return area; // Calculated value ko wapas bhej dena (return type
'float' hai)​
}​

Output:
Room Area (4.5m side): 20.25 sq.m​
Footing Area (1.2m side): 1.44 sq.m​

Important Short Points for Revision


●​ Function \rightarrow Code ka re-usable block for a specific task.
●​ Declaration \rightarrow Tells the compiler about the function.
●​ Definition \rightarrow Contains the function logic.
●​ Call \rightarrow Executes the function.
●​ return \rightarrow Value wapas bhejta hai (agar \text{void} return type ho, toh kuch return
nahi karta).

You might also like