In this blog, we provide the solution of BCA Part-I Previous Year Paper of subject Principle of Programming Languge Through C (PPL Through C) of Year 2016. The solution of this paper is written in EASY and EXAM ORIENTED Language that helps student to how actually written solution in main Rajasthan University (RU) exam.
B.C.A. (Part-I) EXAMINATION, 2016
(Faculty of Science)
(Three-Year scheme of 10+2+3 Pattern)
Paper-134
PRINCIPLES OF PROGRAMMING LANGUAGE (THROUGH ‘C’)
Time Allowed: Three Hours
Maximum Marks – 100
PART-I: (Very Short Answer) consists of 10 questions of 2 marks each. Maximum limit for each questions is up to 40 words.
PART-II: (Short Answer) consists of 5 questions of 4 marks each. Maximum limit of each question is up to 80 words.
PART-III: (Long Answer) consists of 5 questions of 12 marks each with internal choice.
PART-I
PART-II
PART-III
Pseudo code is one of the methods that could be used to represent an algorithm. It is not written in a specific syntax that is used by a programming language and therefore cannot be executed in a computer. It just used for human understand. Basically it acts as a bridge between the program and the algorithm or flowchart.
Machine language is the only language that is directly understood by the computer. The machine language code is written as string of 1’s and 0’s. In this not need any translator program.
When one of the many alternatives is to be selected the switch statement allows a program to select one statement for execution out of a set of alternatives and the remaining statements will be skipped.
Syntax:
switch(expression)
{
case choice1:
statements;
break;
case choice2:
statements;
break;
case choice N:
statements;
break;
default:
statements;
}
The expression must be any integer or character type. The choice 1, choice 2 and choiceN are the possible values which we are going to test with the expression value.
The C program depends upon some header files for function declaration that are used in the program. So, header file is collection of identifiers and generally contains declaration of predefined function. For example, the function printf() and scanf() are declared in stdio.h header file.
An array is finite collection of homogeneous (same type) elements. An array is a data structure that can store multiple elements of same type under one name.
“So, an array is a linear collection of similar data type elements, stored in unique and successive memory locations.”
DECLARATION:
Data_Type Variable_Name [Size];
EXAMPLE:
int arr[7];
The strcat() function joins two strings together. When we combine two strings, this function adds the character of one string to the end of other string.
Syntax:
strcat(String1, String2);
When the function strcat() is executed String2 is appended to String1. The string String2 remains unchanged.
The malloc() function is used to allocate memory space in bytes to the variable of different data types. The function reserves bytes of determined size and return the base address to pointer variable.
Syntax:
Pointer_Variable= (Data_Type *) malloc (Block Size);
The variable which is created or declared inside the any block is called local variable. The local variables only exist inside the specific function that creates them and they are unknown to other functions. The scope of local variable is limited to the block in which it is declared.
The variable which is declared outside the any block is called global variable. The scope of global variable is global and exists throughout the program.
First of all, both structure and union are user defined data type but there are few differences between them, they are:
This function is used for writing characters, strings, integers, float etc. to the file. The fprintf()function contains one more parameter that is file pointer, which points the opened file.
Graphical representation of any problem is called flowchart. A flowchart is a visual representation of the sequence of steps and decisions needed to perform a process. In flowchart various types of graphical symbol is used for represent different activities.
Logical operators are used to check logical relation between two expressions. The expressions may be variables, constants.
OPERATOR |
NAME |
EXAMPLE |
RESULT |
&& |
Logical AND |
5>3 && 5<10 |
1 |
|| |
Logical OR |
8>5 || 8<2 |
1 |
! |
Logical NOT |
!(8!=9) |
0 |
The loop is a block of statements that are executed again and again till a specific condition is satisfied. On the basis of condition checking, the loops are divided into two types, entry-control and exit-control loop. The while loop is entry-control and do-while is exit-control loop.
THE while LOOP:
In while loop the test condition is indicated at the top and it tests the value of the expression before processing the body of the loop.
THE do-while LOOP:
In this the given test condition is evaluated after the execution of the body statement. The do-while loop will execute at least one time even if the condition is false initially.
OPEN A FILE:
A file has to be opened before read and write operations. Opening of file means load the file in RAM. For opening the file, we use the predefined function fopen(). In fopen() function we pass name of the file and its mode of operation as an argument.
CLOSE A FILE:
The file is opened by the fopen() should be closed after the work is over, i.e. we need to close the file after reading and writing operations.
Programming languages exist to enable programmers to develop software effectively. But how efficiently programmers can write software depends on the usability of the languages and tools that they develop with. In order to understand the various constructs of a programming language and its capabilities, it is useful to know some evaluation criteria. Some of the language criterias to evaluate a programming language are:
Readability:
The first and most obvious criteria is certainly readability. Coding should be simple and clear to understand.
Writability:
Writability is a measure of how easily language can be used to code.Most of the language characteristics that affect readability also affect writability.
Reliability:
It refers to type checking (It is testing for type error, either at compile or run time. For example, float height; is more desirable as compare to int height;.), exception handling (It is the ability of program to handle run time error. Remember, handling runtime error are more expensive than compile errors.), aiasing (It is same memory location having more than one name. Which is causes confusion), etc.
Cost:
Total cost of programming should be minimum. For example, cost of trainer, Cost of writing algorithm, Cost of compiling program in the language, Cost of hardware required for program, Cost of maintenance, etc.
Generality:
Language should not be limited to specific application only.
Extensibility:
The programming language should be flexible, must be able to add new constructs.
Standardability:
The programming language should be platform independent.
The C program statements generally execute sequentially in the order in which they are written in the program but in some cases, we may have to change the order of execution of statements.
Decision making statements in a programming language help the programmer to transfer the control from one part to other part of the program. Thus, these decision-making statements facilitate the programmer to determining the flow of control. There are five (5) decision control or selection statements.
The Simple if Statement :
The ‘C’ language uses the keyword if to execute a set of statements or block of statements when the logical condition is true. It has only one option that means it cares only true part.
THE if else STATEMENT :
The if else statement takes care of the true and false conditions. It has two blocks. One block is for if and it is executed when the condition is true. The other block is for else and it is executed when the condition is false.
THE NESTED if else STATEMENTS :
In this kind of statement, we check condition within the condition for executing various statements.
THE if else if LADDER STATEMENT :
The if else if ladder statement helps user to decide one option from multiple options. The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the else if ladder is skipped. If none of the conditions is true, then the final else statement will be executed.
THE switch case STATEMENT :
When one of the many alternatives is to be selected the switch statement allows a program to select one statement for execution out of a set of alternatives and the remaining statements will be skipped.
A collection of data or information that has a name, called the file. Almost all information stored in a computer must be in a file. File is a collection of numbers, symbols and text placed onto the disk.
To work with file handling in C or wants to save program data permanently in secondary storage, C provides the new data type called FILE.
There are four steps to process a file in 'C' language.
DECLARATION OF FILE TYPE POINTER :
The 'C' communicates with files using a new data type called a FILE.
OPEN THE FILE :
A file has to be opened before read and write operations. Opening of file means load the file in RAM. For opening the file we use the predefined function fopen(). In fopen () function we pass name of the file and its mode of operation as an argument.
OPERATION WITH FILE :
Once the file is opened using fopen() function, then file is ready for operation. The FILE type pointers point to the first character of the file. Basically, three types of operation perform with file.
CLOSING A FILE :
The file is opened by the fopen() should be closed after the work is over, i.e. we need to close the file after reading and writing operations.
In C, variables are used to hold data values during the execution of the program. Every variable when declared occupies certain memory location. For example, integer-type variable takes two bytes of memory, character type one byte and float type four bytes of memory.
A pointer is a special variable that stores memory address rather than value. It is called pointer because it points to a particular location in memory by storing the address of that location.
POINTER DECLARATION :
The declaration of pointer variable is similar to normal variable declaration but preceding with asterisk (*) symbol.
Syntax:
Data_Type *Pointer_Name;
Example:
int *ptr;
Here type of variable ptr is ‘pointer to int’ or (int *), or we can say that base type of ptr is int.
INITIALIZATION OF POINTER :
Providing address (memory location) to the pointer is known as initialization of pointer. The Address of (&) operator is used for initialize the pointer variable.
INDIRECTION OPERATOR :