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

COMPUTER PROGRAMMING NOTES

Uploaded by

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

COMPUTER PROGRAMMING NOTES

Uploaded by

mh9153846
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

COMPUTER PROGRAMMING NOTES

T.1. Introduction to problem solving?


Ans. Problem-solving in computer terms refers to the process of identifying,
analyzing, and resolving issues or errors that occur in computer systems,
software, or applications. It involves using logical thinking, technical
knowledge, and strategic approaches to diagnose and fix problems.
Here's a general outline of the problem-solving process in computer terms:
1. Identify the problem: Recognize and describe the issue, including its
symptoms and any error messages.
2. Gather information: Collect relevant data, such as system logs, user
feedback, or debugging output.
3. Analyze the problem: Examine the data to determine the root cause, using
techniques like fault isolation or debugging.
4. Develop a solution: Based on the analysis, create a plan to resolve the
issue, which might involve coding, configuration changes, or other fixes.
5. Implement the solution: Put the plan into action, making any necessary
changes or updates.
6. Test and verify: Check to ensure the solution worked and the problem is
resolved.
7. Document and review: Record the solution and review the process to
improve future problem-solving efforts.
T.2. Compiler & Linker
Ans. Compiler:
Takes your instructions (code)
Translates them into a specific LEGO blueprint (machine code)
Creates a box of individual LEGO pieces (object file) that can't be used alone
Linker:
Takes the box of LEGO pieces (object file) and other necessary boxes
(libraries)
Connects the pieces together according to the blueprint
Builds the complete LEGO castle (executable file) that's ready to play with!
In short:
Compiler: Translates code into machine language, creating individual pieces.
Linker: Combines those pieces into a complete, working program.
This analogy simplifies the process, but it should give you a general idea of
how compilers and linkers work together to turn your code into a
working program.
T.3. Introduction to Algorithm.
Ans. An algorithm is like a list of steps that a computer follows to solve a
problem or complete a task. It's a clear, step-by-step procedure that takes
input (like ingredients) and produces output.
Think of it like this:
Input: The computer takes in some data .
Processing: The computer follows the algorithm's steps
Output: The computer produces a result.
Algorithms can be simple or complex, but they always involve a series of steps
that the computer follows to get the job done!
Some examples of algorithms include:
Sorting a list of names in alphabetical order
Finding the shortest route on a map
Encrypting sensitive information for security
In short, an algorithm is like a recipe that a computer follows to solve a
problem or complete a task.
T.4. Data types & variable
Ans. In computer terms, a data type is like a label that tells the computer
what kind of information you're working with. Think of it like a folder that
helps the computer understand what's inside!
Common data types include:
Numbers (integers, decimals)
Words (text, strings)
True/False values (booleans)
Lists (arrays, collections)
A variable is like a container that holds a value. You can think of it like a
labeled box where you can store a value. The label (variable name) helps you
identify what's inside the box!
Here's an analogy:
Data type is like the type of toy (e.g., building block, doll, car)
Variable is like the toy box that holds the toy (e.g., "My Favorite Toy" box)
When you create a variable, you assign a data type to it, like:
"age" (variable) is an integer (data type) with value 25
"name" (variable) is a string (data type) with value "Siddiq"
This way, the computer knows what kind of information is stored in the
variable and can use it accordingly
T.5. Input/Output constructs arithmetic comparision and logical operators.
Ans. Input/Output constructs:
scanf(): A way to get information from the user (like a question)
printf(): A way to show information to the user (like a message)
Arithmetic operators:
+: Adds two numbers together (like combining apples)
-: Subtracts one number from another (like removing apples)
*: Multiplies two numbers together (like repeating apples)
/: Divides one number by another (like sharing apples)
%: Finds the remaining amount after division (like leftover apples)
Comparison operators:
==: Checks if two things are equal (like same color apples)
!=: Checks if two things are different (like different color apples)
>: Checks if one thing is bigger than another (like more apples)
<: Checks if one thing is smaller than another (like fewer apples)
>= : Checks if one thing is bigger or equal to another (like more or same
apples)
<= : Checks if one thing is smaller or equal to another (like fewer or same
apples)
Logical operators:
&&: Checks if two things are both true (like two true statements)
||: Checks if at least one thing is true (like one true statement)
!: Checks if something is not true (like a false statement)
T.6. Conditional Statement and execution flow of conditional statements.
Ans. Conditional Statement:
A conditional statement is like a decision-making tool that helps your program
decide what to do next. It's like a fork in the road, where your program can
take different paths based on conditions.
In C, conditional statements are like questions that your program asks, and
based on the answer, it decides what to do next.
Execution Flow of Conditional Statements:
The execution flow of conditional statements is like following a map to reach
a destination. Here's how it works:
1. If Statement: Your program asks a question (condition). If the answer is YES
(true), it executes the code inside the if block. If the answer is NO (false), it
skips the if block and moves to the next step.
2. Else Statement: If the answer to the if question is NO (false), your program
executes the code inside the else block.
3. Else-If Statement: Your program asks another question (condition). If the
answer is YES (true), it executes the code inside the else-if block. If the answer
is NO (false), it moves to the next step.
T.7. String & non string operations.
Ans. Strings:
A string is a sequence of characters (like a sentence or a word).
Strings are enclosed in double quotes ("").
Examples: "hello", "goodbye", "abc123".
String Operations:
Concatenation (joining): Joining two strings together using strcat() function.
Length: Finding the length of a string using strlen() function.
Copy: Copying one string to another using strcpy() function.
Compare: Comparing two strings using strcmp() function.
Non-String Operations:
Arithmetic operations (+, -, *, /, %) for numbers.
Comparison operations (==, !=, >, <, >=, <=) for numbers.
Logical operations (&&, ||, !) for true/false values.
Assignment operations (=, +=, -=, *=, /=, %=) for variables.
T.8. Pointer/References in C++
Ans. In C++, pointers and references are ways to work with memory and
variables. Here's a simplified explanation:
Pointers:
A pointer is a variable that holds the memory address of another variable.
Think of it like a map that shows the location of a house (variable).
Pointers are denoted by an asterisk symbol (*).
Example: int* p; // declares a pointer to an integer
References:
A reference is an alias for an existing variable.
Think of it like a nickname for a variable.
References are denoted by an ampersand symbol (&).
Example: int x = 5; int& r = x; // declares a reference to x
T.9. Static & dynamic memory allocation.
Ans. Memory allocation! Think of it like renting a house:
Static Memory Allocation:
Like renting a house for a fixed period (e.g., 1 year).
Memory is allocated at compile-time (when the code is written).
Memory is fixed and cannot be changed later.
Examples: global variables, local variables (inside functions).
Dynamic Memory Allocation:
Like renting a house on a month-to-month basis (flexible duration).
Memory is allocated at runtime (when the program is running).
Memory can be allocated and deallocated as needed.
Examples: malloc(), calloc(), new (in C++), vectors (in C++ STL).
T.10. File I/O operations.
Ans. Put papers in the cabinet (write to a file). Take papers out of the cabinet
(read from a file)
File I/O operations let you do just that with your program!
Here are the basic File I/O operations:
1. Reading from a file:
Open the file (like opening the cabinet)
Read the contents (like taking out papers)
Close the file (like closing the cabinet)
2. Writing to a file:
Open the file (like opening the cabinet)
Write new contents (like putting in new papers)
Close the file (like closing the cabinet)
In C++, you can use:
ifstream (input file stream) for reading
ofstream (output file stream) for writing
fstream (file stream) for both reading and writing

You might also like