TU BCA C Programming 2018 Old Question Solution
TU BCA C Programming 2018 Old Question Solution
Group B
11. What is software process model? Differentiate between cohesion and coupling in
Programming?
A software process model is a systematic approach to developing software that defines the various
phases, activities, and tasks that need to be carried out during the software development life cycle.
The process model provides a framework for software engineers to follow, ensuring that the
software is developed efficiently, on time, and within budget.
There are several different software process models, including the waterfall model, the iterative
model, the spiral model, and the agile model. Each model has its own unique characteristics,
advantages, and disadvantages, and is suitable for different types of software projects.
Cohesion Coupling
Cohesion is the indication of the relationship within Coupling is the indication of the relationships
module between modules
Cohesion shows the module’s relative functional Coupling shows the relative independence among
strength the modules
Cohesion is a degree (quality) to which a component / Coupling is a degree to which a component / module
module focuses on the single thing is connected to the other modules
Keywords are reserved words that have a predefined meaning in the language. These words cannot
be used as identifiers in a program because they have a special meaning in the language. Examples
of keywords in C include if, else, while, for, int, float, char, struct, union, and typedef.
Identifiers are names given to various program elements, such as variables, functions, arrays, and
structures. Identifiers are used to identify and refer to these program elements in the code.
isdentifiers should be chosen so that they contribute to the readability and documentation of the
program.
Valid identifiers:
• count
• _count
• my_variable
• PI
• temp_1
Invalid Identifiers:
• 1count (starts with a digit)
• hello-world (contains a hyphen)
• float (a reserved keyword)
• my long identifier (contains spaces)
• x*y (contains an invalid character)
13. List the operators used in C on the basis of utility. Explain the concept of bitwise operator [2+3]
• Arithmetic operators: Used for performing arithmetic operations such as addition, subtraction,
multiplication, division, and modulus.
• Assignment operators: Used for assigning a value to a variable, such as the = operator.
• Comparison operators: Used for comparing two values and returning a Boolean value of true or
false, such as the ==, !=, <, >, <=, and >= operators.
• Logical operators: Used for performing logical operations such as AND, OR, and NOT, such as the
&&, ||, and ! operators.
• Bitwise operators: Used for performing bitwise operations on the binary representations of
values, such as the &, |, ^, ~, <<, and >> operators.
• Conditional Operator: Used for making decisions based on a condition. The conditional operator
in C is ?: (Ternary Operator).
• sizeof Operator: Used to determine the size of a data type or variable. The sizeof operator in C is
used as sizeof().
Bitwise Operators
In arithmetic-logic unit (which is within the CPU), mathematical operations like: addition,
subtraction, multiplication and division are done in bit-level.
• To perform bit-level operations in C programming, bitwise operators are used.
• Bitwise operators are efficient while doing low level programming or developing embedded
systems.
Bitwise AND:
The output of bitwise AND is 1 if the corresponding bits of two operands is 1. If either bit of an
operand is 0, the result of corresponding bit is evaluated to 0.
Bitwise OR:
The output of bitwise OR is 1 if at least one corresponding bit of two operands is 1.
In C Programming, bitwise OR operator is denoted by |.
In C programming, both while loop and do-while loop are used for executing a block of code
repeatedly until a certain condition is met. However, there are some differences between the two:
Condition checking: In a while loop, the condition is checked at the beginning of each iteration. If
the condition is false, the loop is never executed. On the other hand, in a do-while loop, the
condition is checked at the end of each iteration. This means that the loop is executed at least once,
even if the condition is false.
Loop execution: In a while loop, the loop is executed only if the condition is true. On the other hand,
in a do-while loop, the loop is executed at least once, even if the condition is false.
int x = 100;
// While loop
while (x > 100) {
// This block will never be executed because x is initially 100
x--;
}
// Do-while loop
do {
// This block will be executed once, even though x is initially
100
x--;
} while (x > 100);
if (n == 1) {
printf("1 is neither prime nor composite.");
}
else {
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is a composite number.", n);
}
return 0;
}
15. What is DMA? Write a program to find the largest and smallest number in a list of N number
using DMA. [1+4]
DMA stands for "Dynamic Memory Allocation". It is a feature in C programming language that allows
programs to allocate memory at runtime, rather than at compile time. In Array we have to declare
the size before compiling the program. However, using DMA we can allocate memory dynamically at
runtime. We can even change the size of allocated memory.
// C program to find the largest and smallest number in a list of N
number using DMA
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i, *arr, max, min;
int main() {
int n, i, *arr, max, min;
return 0;
}
16. What is the difference between binary file and text file? Write a C program to write some text
"Welcome to BCA program" in a file test.txt [2+3]
A text file is a file that contains human-readable characters, such as letters, digits, and symbols. The
characters in a text file are typically encoded using ASCII or Unicode character sets. In C, text files are
usually read and written using standard input/output functions such as fscanf() and fprintf().
A binary file, on the other hand, is a file that contains non-textual data, such as images, audio, video,
or executable code. Binary files are usually read and written using low-level input/output functions
such as fread() and fwrite(). Binary files are not human-readable and may contain data that does not
represent a character or a string.
In addition, text files and binary files have different file formats. Text files are usually stored in a
plain text format, with each character represented by a unique code. Binary files are stored in a
binary format, where each byte represents a binary value that can be interpreted as data.
// C program to write some text "Welcome to BCA program" in a file
test.txt
#include <stdio.h>
int main() {
FILE *fp;
fp = fopen("test.txt", "w");
if(fp==NULL) {
exit();
fclose(fp);
return 0;
17. Explain any four graphics functions in C. Write a program to draw two concentric circles with
center (50, 50) and radii 75 and 125. [2+3]
Initgraph()
For writing any graphics program in C we have to call the initgraph function that will initialize the
graphics mode on the computer. Initgraph initializes the graphics system by loading the graphics
driver from disk then putting the system into graphics mode. Initgraph also resets all graphics
settings (color, palette, current position, viewport, etc.) to their defaults.
closegraph()
closegraph function closes the graphics mode, deallocates all memory allocated by graphics system
and restores the screen to the mode it was in before you called initgraph.
void closegraph();
circle():
circle() function is used to draw a circle with a specified center and radius.
The first two arguments specifies the center (x,y) of the circle and the third argument specifies the
radius of the circle.
line():
e.g. line(100,100,200,200);
// program to draw two concentric circles with center (50, 50) and
radii 75 and 125.
#include<graphics.h>
int main()
closegraph();
return 0;
Group C
18. What is one dimensional array? How it is initialized? Write a C program to find the sum of two
matrix of order m×n. [1+1+8]
A one-dimensional array is a collection of variables of the same data type, accessed by a single index
or subscript. In other words, a one-dimensional array is a list of variables of the same data type,
where each variable can be accessed using its index.
In C, a one-dimensional array can be initialized during its declaration or later using a loop. Here's an
example of initializing a one-dimensional array during its declaration:
#include <stdio.h>
int main() {
int m, n, i, j, mat1[m][n], mat2[m][n], sum[m][n];
printf("Enter the order of the matrices: ");
scanf("%d %d", &m, &n);
19. Define structure and union? Write a C program using structure that reads the records of 35
students with members roll, name, address and makes and display the record of students who
have obtained greater than 250 marks. [2+8]
In C, a structure is a collection of variables of different data types grouped together under a single
name. A structure allows us to create a user-defined data type that can store data in a more
organized and meaningful way. Here's an example of defining a structure in C:
struct student {
int roll;
char name[20];
char address[50];
float marks;
};
A union is a special data type in C that allows storing different data types in the same memory
location. This means that a union variable can store only one value at a time, but that value can be of
different types. Here's an example of defining a union in C:
union myUnion {
int x;
char y;
float z;
};
#include <stdio.h>
struct student {
int roll;
char name[20];
char address[50];
float marks;
};
// C program using structure that reads the records of 35 students with members roll, name,
address and makes and display the record of students who have obtained greater than 250 marks.
int main() {
struct student s[35];
int i;
printf("Enter the records of 35 students:\n");
for(i = 0; i < 35; i++) {
printf("Student %d:\n", i + 1);
printf("Roll: ");
scanf("%d", &s[i].roll);
printf("Name: ");
scanf("%s", &s[i].name);
printf("Address: ");
scanf("%s", &s[i].address);
printf("Marks: ");
scanf("%f", &s[i].marks);
}
In C, a function is a group of related statements that perform a specific task. It allows us to break a
large program into smaller and more manageable modules, making the code easier to understand,
test, and maintain. Functions also promote code reuse, as the same function can be called multiple
times from different parts of the program.
• Code reuse: Functions can be reused in multiple parts of the program, reducing code
redundancy and promoting modularity.
• Encapsulation: Functions allow us to encapsulate complex logic and algorithms, making the code
more readable and easier to maintain.
• Testing: Functions can be tested independently, making it easier to detect and fix bugs.
• Efficiency: Functions allow us to write optimized and efficient code by breaking down complex
tasks into smaller and simpler ones.
Function call by value is a mechanism in which a copy of the arguments is passed to the function,
and any changes made to the arguments inside the function are not reflected outside the function.
Here's an example:
#include <stdio.h>
int main() {
int a = 10, b = 20;
printf("Before calling swap function: a = %d, b = %d\n", a, b);
swap(a, b);
printf("After calling swap function: a = %d, b = %d\n", a, b);
return 0;
}
Output:
Before calling swap function: a = 10, b = 20
Inside swap function: x = 20, y = 10
After calling swap function: a = 10, b = 20
Function call by reference is a mechanism in which the memory address of the arguments is passed
to the function, allowing any changes made to the arguments inside the function to be reflected
outside the function. Here's an example:
#include <stdio.h>
int main() {
int a = 10, b = 20;
printf("Before calling swap function: a = %d, b = %d\n", a, b);
swap(&a, &b);
printf("After calling swap function: a = %d, b = %d\n", a, b);
return 0;
}
Output:
Before calling swap function: a = 10, b = 20
Inside swap function: x = 20, y = 10
After calling swap function: a = 20, b = 10