Unit 1

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

Unit 1: Basic Concepts and Programming Structures

1-Mark Questions

1. Define machine language.


Machine language is the lowest-level programming language, consisting of binary
code that the computer’s CPU can directly execute.
2. What is the purpose of a compiler?
A compiler translates high-level programming language code into machine code or an
intermediate code so that it can be executed by the computer.
3. What is a flowchart?
A flowchart is a graphical representation of the steps involved in solving a problem or
performing a process, using symbols like arrows, ovals, and rectangles.
4. Give an example of an application program used in programming.
An example of an application program used in programming is Visual Studio Code,
which is used for coding in various programming languages.
5. What is the difference between system software and application software?
System software manages hardware resources and provides a platform for running
application software (e.g., Windows OS), whereas application software is designed to
perform specific tasks for the user (e.g., Microsoft Word).

3-Marks Questions

1. Explain the evolution of programming languages.


Programming languages have evolved from machine language (binary) to assembly
language, which uses mnemonics for instructions, to high-level languages like
Fortran, C, and Python. Modern languages like Python and JavaScript focus on ease
of use and portability, making programming more accessible to a wider audience.
2. What are the main components of system software?
The main components of system software include the operating system, device
drivers, utility programs, and the kernel, all of which work together to manage
hardware resources and provide an environment for running application software.
3. Describe the basic structure of an algorithm.
The basic structure of an algorithm consists of a clear set of instructions that define
the input, processing, and output steps required to solve a problem. It usually involves
initialization, a loop or sequence of operations, and a termination condition.
4. Compare and contrast a compiler and an interpreter.
A compiler translates the entire program into machine code at once, producing an
executable file, while an interpreter translates and executes code line by line. A
compiler is faster at execution but requires more time for the initial translation, while
an interpreter allows for quicker testing and debugging.
5. How do flowcharts help in programming?
Flowcharts help programmers visualize the steps of a process, making it easier to
understand the logic and identify errors or inefficiencies. They serve as a blueprint for
writing code and provide a clear structure for problem-solving.

10-Marks Questions

1. Write a detailed note on the evolution of programming languages.


The evolution of programming languages began with machine language, which was
specific to a particular computer architecture. Assembly language was developed to
simplify machine code using human-readable mnemonics. The introduction of high-
level languages like Fortran in the 1950s allowed for more complex and portable
programs. Over time, languages like C and Java brought more flexibility and
efficiency. Modern languages like Python, JavaScript, and Go prioritize ease of use,
speed, and scalability, making software development more efficient and accessible.
2. Explain system software components with examples.
System software includes:
o Operating system (OS): The primary software that manages hardware
resources and provides an interface for users and application software (e.g.,
Windows, Linux).
o Device drivers: Programs that control and manage hardware devices like
printers, mice, and keyboards.
o Utility programs: Programs that perform maintenance tasks, such as file
management and antivirus software.
o Kernel: The core part of the OS that manages system resources and allows
communication between hardware and software.
3. Discuss the steps to create and specify an algorithm with a flowchart.
To create an algorithm, follow these steps:
1. Define the problem: Understand the problem and determine the desired
outcome.
2. Identify the input and output: Determine what data will be provided and
what the output should be.
3. Design the algorithm: Break down the problem into smaller steps.
4. Draw a flowchart: Use standard symbols (ovals for start/end, rectangles for
processes, diamonds for decision points) to represent the steps.
5. Test the algorithm: Verify the algorithm with sample data to ensure it works
as expected.

Unit 2: Data Types and Operators, Variables, Sequences, and Iteration

1-Mark Questions

1. Name any two logical operators.


AND (&&), OR (||)
2. Define a local variable.
A local variable is a variable that is declared within a function or block and can only
be accessed within that scope.
3. What is a tuple?
A tuple is an ordered, immutable collection of elements, typically used to group
related data together (e.g., (1, 2, 3)).
4. State any two precedence rules in expressions.
o Parentheses () have the highest precedence.
o Multiplication (*) and division (/) have higher precedence than addition (+)
and subtraction (-).
5. Give one example of a bitwise operator.
AND (&)

3-Marks Questions
1. Differentiate between local and global variables.
o Local variables: Declared within a function and accessible only within that
function.
o Global variables: Declared outside any function and can be accessed
throughout the program.
2. Explain the significance of accumulation patterns in sequences.
Accumulation patterns involve repetitive operations, such as summing values in a
sequence or accumulating results over time, useful in loops or iterative processes for
problems like calculating totals or averages.
3. Describe the concept of sequence mutation with examples.
Sequence mutation refers to modifying an element in a sequence like a list or array.
For example, in Python, lst[0] = 10 changes the first element of the list lst to 10.
4. List and explain the types of data types in programming.
o Primitive data types: Integer, float, character, boolean.
o Composite data types: Arrays, lists, tuples, dictionaries.
o User-defined data types: Structs, classes, enums.
5. Write a short note on bitwise operators.
Bitwise operators operate on binary numbers at the bit level. Common bitwise
operators include AND (&), OR (|), XOR (^), NOT (~), and shifts (<<, >>).

10-Marks Questions

1. Elaborate on all types of operators used in programming with examples.


Operators in programming include:
o Arithmetic operators: +, -, *, /, % (e.g., 3 + 4 = 7).
o Relational operators: ==, !=, <, >, <=, >= (e.g., a > b).
o Logical operators: &&, ||, ! (e.g., a && b).
o Bitwise operators: &, |, ^, ~, <<, >> (e.g., 5 & 3 = 1).
o Assignment operators: =, +=, -=, *=, /= (e.g., x += 2).
o Unary operators: ++, --, - (e.g., --a).
o Ternary operator: condition ? true : false (e.g., a > b ? a : b).
2. Explain variables, their types, and how they are used in different contexts.
Variables store data values. Types include:
o Primitive types: Integers (e.g., int), floats (e.g., float), characters (e.g.,
char).
o Composite types: Arrays (e.g., int[]), lists (e.g., Python lists).
o User-defined types: Classes and structures in object-oriented programming
(e.g., class Employee). Variables are used in different contexts like storing
user input, counting iterations in loops, or holding results from functions.
3. Discuss sequences and iteration with suitable examples and applications.
Sequences involve ordered collections of data, and iteration is the process of
repeatedly executing a set of instructions. For example, iterating through an array to
find the largest number:

python
Copy code
arr = [1, 3, 5, 2]
max_val = arr[0]
for num in arr:
if num > max_val:
max_val = num
Sequences and iteration are crucial in problems like searching, sorting, and data
processing.

Unit 3: Conditional Statements, Loops, Arrays, and User-Defined Data Types

1-Mark Questions

1. Define a nested iteration.


A nested iteration refers to a loop within another loop. The inner loop is executed
fully for each iteration of the outer loop.
2. What is a 2-dimensional array?
A 2-dimensional array is an array of arrays, where each element is another array. It
can be visualized as a table with rows and columns (e.g., arr[3][3]).
3. State the purpose of an if-else statement.
An if-else statement allows a program to make decisions by executing different blocks
of code based on a condition.
4. Give an example of a user-defined data type.
An example of a user-defined data type is a struct in C or a class in Python, which
allows users to create complex types with multiple attributes.
5. What is the syntax for declaring an array?
The syntax for declaring an array is:
o In C: dataType arrayName[size]; (e.g., int arr[5];)
o In Python: arrayName = [elements] (e.g., arr = [1, 2, 3]).

3-Marks Questions

1. Write a short note on nested loops.


Nested loops involve placing one loop inside another, allowing for the iteration over
multi-dimensional data structures like 2D arrays or matrices. The inner loop runs
completely for each iteration of the outer loop.
2. How are arrays declared and used in programming?
Arrays are declared with a specified size and type. In C, the declaration syntax is
dataType arrayName[size], and in Python, arrays (or lists) are created with square
brackets [ ]. Arrays store multiple elements of the same type and allow accessing
elements using indices.
3. Compare for and while loops with examples.
o For loop: Used when the number of iterations is known or fixed.
Example:

c
Copy code
for (int i = 0; i < 5; i++) { printf("%d\n", i); }

o While loop: Used when the number of iterations is not known beforehand, and
the loop continues as long as a condition is true.
Example:

c
Copy code
int i = 0;
while (i < 5) { printf("%d\n", i); i++; }
4. What are user-defined data types? Explain with an example.
User-defined data types are data types created by the programmer to represent
complex structures. For example, in C, a struct can define a user-defined data type
to store multiple related data elements:

c
Copy code
struct Person {
char name[50];
int age;
};

5. Describe the concept of multidimensional arrays.


Multidimensional arrays are arrays that have more than one dimension (e.g., 2D
arrays, 3D arrays). They are used to store data in a table-like structure. For example, a
2D array can represent a matrix:

c
Copy code
int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

10-Marks Questions

1. Write a program to demonstrate the use of arrays in solving real-world


problems.
A real-world example of arrays could be calculating the average of test scores:

c
Copy code
#include <stdio.h>
int main() {
int scores[5] = {80, 85, 90, 95, 100};
int sum = 0;
for (int i = 0; i < 5; i++) {
sum += scores[i];
}
float average = sum / 5.0;
printf("Average score: %.2f\n", average);
return 0;
}

2. Discuss conditional statements and their role in decision-making within a


program.
Conditional statements like if, else, switch, and else if allow the program to
make decisions based on conditions. They determine which block of code should be
executed, enabling dynamic responses depending on the input or program state.
3. Explain arrays, their types, and applications with suitable examples.
Arrays are used to store multiple values of the same type in contiguous memory
locations. Types include:
o One-dimensional arrays: A simple list of values.
o Multidimensional arrays: Used for matrices, tables, etc. Example of a 1D
array in C:

c
Copy code
int arr[5] = {10, 20, 30, 40, 50};

Example of a 2D array in C:

c
Copy code
int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};

Unit 4: Dictionaries, Functions/Methods

1-Mark Questions

1. Define a dictionary.
A dictionary is a data structure that stores key-value pairs, where each key is unique
and maps to a specific value. In Python, it is defined as {key: value}.
2. What is recursion?
Recursion is a process where a function calls itself to solve smaller instances of the
same problem.
3. Name two dictionary operations.
o get(key): Retrieves the value associated with the key.
o update(): Adds or updates a key-value pair in the dictionary.
4. What is a library function?
A library function is a pre-defined function provided by a programming language or
library, which can be called to perform specific tasks, like mathematical calculations
or input/output operations.
5. State the advantage of modular programming.
Modular programming allows for better code organization, reusability, and
maintainability by breaking a program into smaller, manageable functions or modules.

3-Marks Questions

1. Explain the basics of dictionaries in programming.


A dictionary is a collection of key-value pairs. Each key must be unique, and it maps
to a specific value. It is commonly used for fast lookups and is supported in languages
like Python and JavaScript.
2. Describe the advantages of using functions in programming.
Functions promote code reusability, modularity, and readability. They allow breaking
down a program into smaller, manageable pieces, making it easier to debug and
maintain.
3. Write a short note on positional parameter passing.
Positional parameter passing refers to passing arguments to a function based on their
position in the function call. The first argument corresponds to the first parameter in
the function definition, the second argument to the second parameter, and so on.
4. Explain the concept of recursion with an example.
Recursion is when a function calls itself to solve a problem. A simple example is
calculating the factorial of a number:

c
Copy code
int factorial(int n) {
if (n == 1) return 1;
return n * factorial(n - 1);
}

5. What is dictionary accumulation?


Dictionary accumulation is the process of iteratively adding or updating key-value
pairs in a dictionary, often to accumulate results during a computation.

10-Marks Questions

1. Discuss functions and their importance in modular programming.


Functions allow modular programming by encapsulating tasks in self-contained units.
This reduces code duplication, improves readability, and makes the code easier to test
and maintain. Functions can be reused in different parts of the program, saving time
and effort.
2. Write a program to demonstrate passing arrays to functions.
Example: Passing an array to a function to calculate the sum of elements:

c
Copy code
#include <stdio.h>
int sum(int arr[], int size) {
int total = 0;
for (int i = 0; i < size; i++) {
total += arr[i];
}
return total;
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
int result = sum(arr, 5);
printf("Sum: %d\n", result);
return 0;
}

3. Explain dictionary operations, methods, and applications with examples.


Dictionary operations include:
o get(): Retrieves the value for a key.
o update(): Adds or modifies key-value pairs. Example in Python:

python
Copy code
my_dict = {'a': 1, 'b': 2}
print(my_dict.get('a')) # Output: 1
my_dict.update({'c': 3})
print(my_dict) # Output: {'a': 1, 'b': 2, 'c': 3}

Unit 5: File Handling and Memory Management

1-Mark Questions

1. Define a file in programming.


A file in programming is a collection of data stored on a storage device (e.g., hard
drive) that can be read, written, and manipulated by a program.
2. What is a .csv file?
A .csv (Comma-Separated Values) file is a text file used to store tabular data, where
each line represents a row and each value is separated by commas.
3. Name any one memory management operation.
One memory management operation is allocation, which is the process of reserving
memory space for variables and data structures.
4. What is the purpose of reading data from a file?
Reading data from a file allows a program to access stored information for processing,
analysis, or display.
5. State one advantage of using files in programming.
Files provide persistent storage, meaning the data can be saved and retrieved even
after the program ends or the computer is shut down.

3-Marks Questions

1. Explain basic file operations in programming.


Basic file operations include:
o Opening a file for reading or writing.
o Reading data from a file.
o Writing data to a file.
o Closing the file after operations are complete.
2. Write a short note on memory management.
Memory management refers to the process of efficiently allocating, using, and
deallocating memory in a program. It involves operations like allocation (reserving
memory), deallocation (freeing memory), and garbage collection.
3. How is data written to a .csv file?
Data is written to a .csv file by formatting values as strings and separating them with
commas. In Python, you can use the csv module:

python
Copy code
import csv
data = [['Name', 'Age'], ['John', 25], ['Jane', 28]]
with open('data.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(data)

4. Describe the concept of file handling in programming.


File handling involves opening, reading, writing, and closing files. It allows programs
to interact with data stored in files, such as reading configuration data or saving user
input.
5. Compare file reading and writing operations.
o Reading from a file extracts data for processing. Methods include read() for
full content or readline() for line-by-line reading.
o Writing to a file involves saving data. Methods include write() to write
strings or writelines() to write lists.

10-Marks Questions

1. Discuss the concepts of file handling with examples of reading and writing
operations.
File handling allows interaction with files through opening, reading, writing, and
closing. Example:

python
Copy code
# Writing to a file
with open('output.txt', 'w') as file:
file.write("Hello, world!")

# Reading from a file


with open('output.txt', 'r') as file:
content = file.read()
print(content) # Output: Hello, world!

2. Explain the importance of memory management in programming with examples.


Memory management is crucial for efficient use of system resources. Example:
o Dynamic memory allocation allows programs to request memory as needed
during execution. This helps handle large datasets.
o Memory leaks occur when allocated memory is not properly freed, leading to
wasted resources.
3. Write a program to read data from and write data to a .csv file.

python
Copy code
import csv

# Writing to a CSV file


data = [['Name', 'Age'], ['Alice', 30], ['Bob', 25]]
with open('people.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(data)

# Reading from the CSV file


with open('people.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
print(row)

You might also like