Professional Documents
Culture Documents
6 Marks CS
6 Marks CS
6 Marks CS
6 MARKS:
INPUT DEVICES:
These are used to enter data and commands into the computer. Examples
include:
1. Keyboard:Used to input text, numbers, and commands.
2. Mouse:Used to navigate and select items on the screen.
3. Scanner:Converts physical documents or images into digital format.
4. Microphone:Captures audio input, like voice commands or recordings.
5. Touchscreen:Allows users to input data or make selec;ons by touching the
display.
OUTPUT DEVICES:
These display or provide processed data from the computer to the user.
Examples include:
1. Monitor:Displays visual output, including text, images, and videos.
2. Printer:Produces hard copies of documents, images, or other content.
3. Speaker:Outputs audio such as music, voice, or system sounds.
4. Projector:Displays computer output on a larger screen or surface, oUen used
in presenta;ons.
5. Headphones:Provides audio output for private listening.
ALGORITHM:
Start
Read values a,b,c
Check if ((a>b) and (a>c) then
Print ”a is big”
Else if (b>c) then
Print “b is big”
Else print “c is big”
Stop
FLOWCHART:
4.explain in detail the classifica;on of computers?
- Computers can be classified based on various criteria, including size,
func;onality, purpose, and architecture. Here's a detailed classifica;on:
2. BASED ON FUNCTIONALITY:
- Analog Computers: Process con;nuous signals and perform mathema;cal
opera;ons based on analog principles. They are used in scien;fic and
engineering applica;ons.
- Digital Computers: Operate on discrete data and execute instruc;ons based
on binary digits (0s and 1s). Most modern computers fall into this category.
- Hybrid Computers:Combine features of both analog and digital computers.
They are suitable for tasks requiring real-;me data processing and control
applica;ons.
3. BASED ON PURPOSE:
- General-Purpose Computers: Designed for various tasks and applica;ons,
such as personal compu;ng, business opera;ons, and educa;on.
- Special-Purpose Computers: Built for specific func;ons or industries, such as
ATM machines, point-of-sale systems, and gaming consoles.
4. BASED ON ARCHITECTURE:
- single-User Computers: Designed for individual use, such as personal
computers and worksta;ons.
- Mul;-User Computers:Allow mul;ple users to access and use the system
simultaneously. Mainframes and some servers fall into this category.
- Distributed Computers: Consist of mul;ple computers connected in a
network, sharing resources and processing tasks collec;vely. Examples include
clusters and grid compu;ng systems.
FIRST GENERATION(1940-1956):
• HARDWARE TECH:
- Vaccum tubes used,circuitry,magne;c drums for memory.
-Input through punched cards.
-Output through printouts.
• SOFTWARE TECH:
-wriken in machine language(‘s and ‘s code).
-Solve one problem at a ;me
• COMPUTING CHARACTER:
-Millisec(1 millisec= 1*10^-3s)
• APPEARANCE:
-Big in size.
-Large room for installa;on
• EXAMPLE:
-UNIVAC
-ENIAC
-EDVAC
• ADVANTAGE :
-Execute complex mathema;cal problems
• DISADVANTAGE:
-Large no.of vaccum tubes, generate heat, so malfunc;on due to heat.
-High maintenance & large amt.of electricity used.
-Non transformable due to its big size
SECOND GENERATION(1956-1963):
• HARDWARE TECH:
-transistor used instead of vaccum tubes
-magne;c core(primary memory)
-magne;c taps,magne;c disk(secondary memory)
-punched cards(input)
-printouts(output)
• SOFTWARE TECH:
-instruc;ons in assembly language
-high level programming language(COBOL,FORTRAN)
• COMPUTING CHARACTER:
-Microsec(1microsec=1*10^-6s)
• APPEARANCE:
-Transistor small so computer size reducesd
• APPLICATION:
-special purpose
• ADVANTAGE:
-easy to write assembly language then machine language
• DISADVANTAGE:
-i/o not improved
-high cost
THIRD GENERATION(1964-1971):
• HARDWARE TECH:
-integrated circuit chips(IC) used
-IC chips -many transistors on silicon chip ,so type of semiconductor
-high speed efficiency
-keyboard(input)
-displayed in monitor(output)
• SOFTWARE TECH:
-keyboard ,monitor -interfaced through os
-mul;ple applica;ons run through os
-high level language used instead of assembly and machine language
• COMPUTING CHARACTER:
-nanosec(1 nanosec=1*10^-9s)
• APPEARANCE:
-Small
• APPLICATION:
-produced commercially
-general purpose usage
• EXAMPLE:
-IBM system 370
-PDP II
• ADVANTAGE:
-Less power, less heat,low maintanence
-low cost as individual componets doesn’t require to assemble manually
-mul;-tasking,easy to program high level language
• DISADVANTAGE:
-small storage capacity
-computer degraded-when large applica;on, complex calcula;on done
-need to be kept at air-condi;oned room
FOURTH GENERATION(1971-PRESENT):
• HARDWARE TECH:
-use large scale integra;on technology
-thousands of transistors integrated on small silicon chip(LSI TECH0
-VSLI (100’s of transistor integrated)
• SOFTWARE TECH:
-os like MS-DOC,MS- window developed
-support graphical user interface(GUI)
-high level programming language used
• COMPUTING CHARACTER:
-picosec(1 picosec=1*10^-2s)
• APPEARANCE:
-small ,fit in the palm of hand
• APPLICATION:
-commercial use
-personal computers(home user)
• EXAMPLE:
-intel 14004 chip
-cpu,memory located in single chip
• ADVANTAGE:
-smaller,cheap(micro-processor)
-storage capacity(large,faster)
-portable,reliable,less heat,less maintenance
-user friendly
• DISADVANTAGE:
-LSI,VLSI(complex tech) so, chips not easily processed
-work on instruc;on given by programmers
#include <stdio.h>
int main() {
double principalAmount;
float rateOfInterest;
int numberOfYears;
double simpleInterest;
printf("Enter the principal amount: ");
scanf("%lf", &principalAmount);
printf("Enter the rate of interest (in percentage): ");
scanf("%f", &rateOfInterest);
printf("Enter the number of years: ");
scanf("%d", &numberOfYears);
simpleInterest = (principalAmount * rateOfInterest * numberOfYears) /
100.0;
printf("Simple Interest = %lf\n", simpleInterest);
return 0;
}
return 0;
}
10. illustrate any 3 condi;onal statements with an example.
1. if Statement:
The if statement tests a condi;on. If the condi;on is true, the code inside the
block {} following the if statement is executed.
#include <stdio.h>
int main() {
int num = 10;
if (num > 0) {
prin€("The number is posi;ve.\n");
}
return 0;
}
2. If-else Statement:
The if-else statement tests a condi;on. If the condi;on is true, the code inside
the if block is executed. Otherwise, the code inside the else block is executed.
#include <stdio.h>
int main() {
int num = -5;
if (num >= 0) {
prin€("The number is non-nega;ve.\n");
} else {
prin€("The number is nega;ve.\n");
}
return 0;
}
3. if-else-if Ladder:
This is an extension of the if-else statement. Here, mul;ple condi;ons are
checked using else if. Only one block of code among several if-else-if blocks is
executed based on the condi;on.
#include <stdio.h>
int main() {
int score = 85;
if (score >= 90) {
prin€("Grade A\n");
} else if (score >= 80) {
prin€("Grade B\n");
} else if (score >= 70) {
prin€("Grade C\n");
} else {
prin€("Grade F\n");
}
return 0;
}
return 0;
}
b. Logical Operators (3)
-Logical operators are used to perform logical opera;ons. They return a
Boolean result (either true or false).
1. Logical AND &&: Returns true if both operands are true.
2. Logical OR ||: Returns true if at least one of the operands is true.
3. Logical NOT !: Returns true if the operand is false and vice versa.
EXAMPLE:
#include <stdio.h>
int main() {
int x = 5, y = 10;
if (x > 0 && y > 0) {
prin€("Both x and y are posi;ve.\n");
} else {
prin€("At least one of x and y is not posi;ve.\n");
}
if (x > 0 || y > 0) {
prin€("At least one of x and y is posi;ve.\n");
} else {
prin€("Both x and y are not posi;ve.\n");
}
if (!(x == y)) {
prin€("x is not equal to y.\n");
} else {
prin€("x is equal to y.\n");
}
return 0;
}
12. Write a C program to calculate Average and Grade of Students by
implementing various data types. ( take your own parameters).
- #include <stdio.h>
int main() {
char name[50];
int math, science, english;
float average;
char grade;
printf("Enter student's name: ");
scanf("%s", name);
printf("Enter math score: ");
scanf("%d", &math);
printf("Enter science score: ");
scanf("%d", &science);
printf("Enter english score: ");
scanf("%d", &english);
average = (math + science + english) / 3.0;
if (average >= 90) {
grade = 'A';
} else if (average >= 80) {
grade = 'B';
} else if (average >= 70) {
grade = 'C';
} else if (average >= 60) {
grade = 'D';
} else {
grade = 'F';
}
printf("\nStudent Name: %s\n", name);
printf("Average Score: %.2f\n", average);
printf("Grade: %c\n", grade);
return 0;
}
13. Construct a C program to display odd numbers from 1 to N using a user-
defined function.
#include<stdio.h>
Int main()
{
Int i,numbers;
Printf(“\n please enter the maximum limit;”);
Scanf(“%d”,& number);
Printf(“\n odd no. between 1 and %d are :\n”,numbers);
For (i=1;,i<= number;i++)
{
If(I % 2!=0)
{
Printf(“%d\t”,i);
}
}
}
Return 0;
14. Express any three string handling functions in C with their syntaxes. Give
Example.
Syntax:
int strcmp(const char *str1, const char *str2);
Example:
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "apple";
char str2[] = "banana";
int result = strcmp(str1, str2);
if (result < 0) {
printf("str1 is less than str2\n");
} else if (result > 0) {
printf("str1 is greater than str2\n");
} else {
printf("str1 is equal to str2\n");
}
return 0;
}
15. Construct a C Program to compute the sum of integers stored in a one
dimensional array.
#include <stdio.h>
int main() {
int arr[100];
int n, i, sum = 0;
prin€("Enter the number of elements (up to 100): ");
scanf("%d", &n);
prin€("Enter %d integers:\n", n);
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
sum += arr[i];
}
prin€("Sum of the integers: %d\n", sum);
return 0;
}
18.Write a C program to copy the content of a string variable from one variable
to another variable and find the length of it.
#include <stdio.h>
#include <string.h>
int main() {
char sourceString[] = "Hello, World!";
char des;na;onString[50];
int length;
strcpy(des;na;onString, sourceString);
length = strlen(des;na;onString);
prin€("Copied String: %s\n", des;na;onString);
prin€("Length of the Copied String: %d\n", length);
return 0;
}
19.Write a program to invoke the func;on by passing the address of the radius
of the circle to the func;on for finding the area and perimeter of a circle.
#include<stdio.h>
#include<math.h>
Int main()
{
Float radius;
Float area;
Float perimeter;
Prin€(“enter radius of circle\n”);
Scanf(“%f,&radius);
Area=m_pi*radius*radius;
Perimeter=2*m_pi*radius;
Prin€(“area of circle is %f and perimeter is %f”,area,perimeter);
Return 0;
}
20.Write a C program to define a structure named state, with fields state name,
number of districts, and total popula;on. Read and display the data.
#include <stdio.h>
struct State {
char stateName[50];
int numberOfDistricts;
long long totalPopula;on;
};
int main() {
struct State s;
prin€("Enter State Name: ");
scanf("%s", s.stateName);
prin€("Enter Number of Districts: ");
scanf("%d", &s.numberOfDistricts);
prin€("Enter Total Popula;on: ");
scanf("%lld", &s.totalPopula;on);
prin€("\nState Name: %s\n", s.stateName);
prin€("Number of Districts: %d\n", s.numberOfDistricts);
prin€("Total Popula;on: %lld\n", s.totalPopula;on);
return 0;
}
21.Discuss the different types of dynamic memory alloca;on func;ons in C
1.malloc():
• Stands for “memory alloca;on”.
• Allocates a block of memory of a specified size in bytes.
• Does not ini;alize the allocated memory; it may contain garbage
values.
• Returns a pointer to the first byte of the allocated memory block.
2.calloc():
• Stands for “con;guous alloca;on”.
• Allocates mul;ple blocks of memory, each of the specified size,
ini;alizing all bytes to zero.
• Returns a pointer to the first byte of the allocated memory block.
3.realloc():
• Stands for “re-alloca;on”.
• Adjusts the size of the previously allocated memory block.
• If the new size is larger, it may move the block to a new loca;on;
exis;ng data is preserved up to the smaller of the new and old sizes.
• If the new size is smaller, the excess bytes at the end of the block
are freed.
• Returns a pointer to the resized memory block. If the block is
moved, the old pointer may become invalid, so it’s crucial to assign the
returned pointer back to the original pointer.
#include <stdio.h>
void callByValue(int x) {
x = x + 10; // Modifying the formal parameter
prin€("Inside callByValue: %d\n", x);
}
int main() {
int num = 20;
prin€("Before callByValue: %d\n", num);
callByValue(num);
prin€("AUer callByValue: %d\n", num);
return 0;
}
CALL BY REFERENCE:
In call by reference, the address of the actual parameter is passed to the formal
parameter. Any changes made to the formal parameters inside the called
func;on will affect the actual parameters in the calling func;on since they are
poin;ng to the same memory loca;on.
#include <stdio.h>
void callByReference(int *ptr) {
*ptr = *ptr + 10;
prin€("Inside callByReference: %d\n", *ptr);
}
int main() {
int num = 20;
prin€("Before callByReference: %d\n", num);
callByReference(&num);
prin€("AUer callByReference: %d\n", num);
return 0;
}
2. Performance:
- C provides a level of performance op;miza;on, as it's a low-level language.
This is beneficial for real-;me or resource-intensive game applica;ons.
3. Portability*
- Games developed in C can be more portable across pla€orms compared to
some higher-level languages, given that you manage dependencies and
pla€orm-specific code effec;vely.
5. Memory Management:
- Memory management is manual in C, which means developers need to
handle memory alloca;on and dealloca;on. This can be both an advantage (for
performance reasons) and a challenge (prone to memory leaks or errors).
1. Graphics Rendering:
- C lacks built-in graphics libraries for game development. You would need to
integrate external libraries like SDL or OpenGL for graphics rendering, which
may require addi;onal learning and setup.
2. Game Physics:
- Implemen;ng realis;c physics for the bird's flight and collision detec;on
with pipes or obstacles can be complex. You'd need to manage veloci;es,
gravity, and collision detec;on algorithms efficiently.
3. input Handling:
- Handling user input to control the bird's flight (e.g., tapping to make the bird
fly) requires efficient event handling and response mechanisms.
4. Cross-Pla€orm Compa;bility:
- Ensuring that the game runs consistently across different pla€orms can be
challenging. You'd need to manage pla€orm-specific code and dependencies.
5. Memory Management:
- C requires manual memory management. Ensuring efficient memory
alloca;on and dealloca;on to avoid memory leaks or segmenta;on faults is
crucial.
6. User Experience:
- Crea;ng engaging visuals, sound effects, and user interfaces within the
limita;ons of C can be challenging. You may need to op;mize assets and code
to maintain a smooth and enjoyable user experience.
7. Performance Op;miza;on:
- Given that C is a low-level language, op;mizing the game for performance,
especially on resource-constrained devices, is essen;al. This includes
op;mizing rendering, upda;ng game states, and managing resources efficiently
2. GLOBAL VARIABLES:
- Global variables are declared outside of any func;on and are accessible
throughout the en;re program.
- They are allocated in the global or sta;c memory space, depending on their
storage specifier (e.g., sta;c).
- Global variables retain their values throughout the life;me of the program,
making them accessible from any part of the code.
Example:
int globalVar = 20; // This is a global variable
void anotherFunc;on() {
// You can access globalVar here
// ... rest of the code
}
CONSIDERATIONS IN EMBEDDED C:
- Memory Usage: Global variables consume more memory and can lead to
memory constraints in embedded systems with limited resources.
- visibility: Over-reliance on global variables can make the code less modular
and harder to maintain.
- ini;aliza;on: Global variables are ini;alized only once at the start of the
program, whereas local variables are ini;alized every ;me their enclosing
func;on or block is called.
In embedded C programming, due to resource constraints and real-;me
requirements, it's essen;al to judiciously use global variables and prefer local
variables wherever possible to op;mize memory usage and improve code
modularity.
2. Global Variables:
- Variables declared outside func;ons that have global scope, accessible
throughout the program.
3. Func;on Declara;ons:
- Prototypes or declara;ons of func;ons that will be defined later in the
program.
4. Main Func;on:
- The entry point of the program where execu;on begins. It contains the
primary logic or calls other func;ons.
5. User-Defined Func;ons:
- Func;ons that encapsulate specific tasks or func;onali;es to modularize the
code.
7. Configura;on Se‡ngs:
- Ini;aliza;on se‡ngs for peripherals, ;mers, communica;on interfaces, and
other hardware components used in the embedded system.
#include <stdio.h>
vola;le unsigned int *regAddress = (unsigned int *)0x40020000;
int main() {
unsigned int value = 0xAA;
prin€("Ini;al value at register: 0x%X\n", *regAddress);
*regAddress = value;
prin€("Value wriken to register: 0x%X\n", *regAddress);
return 0;
}
1. Graphics Rendering:
- C doesn't have built-in graphics libraries tailored for game development.
You'd need to integrate external libraries like SDL or OpenGL for rendering the
game graphics, which can require addi;onal setup and learning.
2. Game Logic:
- Implemen;ng the logic for snake movement, growth, collision detec;on
with walls or itself, and food genera;on requires careful planning and efficient
algorithms.
3. Input Handling:
- Managing user input for controlling the snake's direc;on (e.g., arrow keys)
needs efficient event handling and response mechanisms.
4. Memory Management:
- C requires manual memory management. Ensuring efficient alloca;on and
dealloca;on of memory for snake segments, food items, and other game
elements is crucial to prevent memory leaks or errors.
5. Scalability:
- Designing the game to be scalable, allowing for increasing difficulty levels,
addi;onal features, or op;miza;ons, requires though€ul design and modular
coding prac;ces.
6. User Experience:
- Crea;ng engaging visuals, sound effects, and user interfaces within the
limita;ons of C can be challenging. Op;mizing assets and code to maintain a
smooth and enjoyable user experience is essen;al.
7. Performance Op;miza;on:
- C being a low-level language, op;mizing the game for performance,
especially on resource-constrained devices, is vital. This includes op;mizing
rendering, upda;ng game states, and managing resources efficiently.