Co4 Qestions-Assgn PDF

You might also like

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

KL University

I – B.Tech - I Semester – Internal Examinations – July – 2017


Test – IV
Problem Solving & Computer Programming (17CS1101)
Time : 1 ½ Hours Total Marks: 30
Answer All Questions (Internal Choice for each question)

CO:4 B.T.L: 2,2 10 Marks

1. Define a structure date containing 3 integers day, month, year. Write a program using
functions to read data, to validate the date entered by the user and then print the date on the
screen. For example, if you enter 29,2,2010 then that is an invalid date as 2010 is not a leap
year. Similarly 31,6,2017 is invalid date as June does not have 31 days.

2. There are 100 records present in a file with the following structure:
struct date
{
int d, m, y ;
};
struct employee
{
int empcode[6] ;
char empname[20] ;
struct date join_date ;
float salary ;
};
Write a program to read these records, arrange them in ascending order of join_date and
write them in to a target file.

3. Implement the following functions. Their meanings are given below.


a) int strCount (char *filename);
returns a count of no. of strings in a text file identified by the filename in the parameter.
b) int sentenceCount (char *filename);
returns a count of no. of sentences in the identified text file. A sentence is detected when
the last character of a word is the full stop.
Test these functions on text files. A sample text file: sample

4. Write a c program a string consisting of lowercase English alphabetic letters. In one


operation, he can delete any pair of adjacent letters with same value. For example, string
"aabcc" would become either "aab" or "bcc" after operation. To do this, he will repeat the
above operation as many times as it can be performed and to find & print’s non-reducible
form.
Note: If the final string is empty, print Empty String.
Input: aaabccddd
Output: abd
Input: baab
Output: Empty String
5. Define a structure named census with the following three members:
 A character array city[] to store names
 A long integer to store population of the city
 A float member to store the literacy level.
Write a program to read details of 5 cities randomly and sort the list based on literacy level.

6. Sunny is fond of Vowels. In a given line of text he wanted to see all lower-case
vowels in uppercase & vice-versa. Write a C program to implement Sunny’s wish.
Ex:
Input: India is my country.
Output: IndIA Is my cOUntry.

7. Define a structure type called subscriber that contains the components as name ,
street, address , and monthly_bill (i.e., how much the subscriber owes). Write a C program to
list all the subscribers whose monthly bill is minimal(<750/-).

8. (a). Write a function that finds the length of a given single linked list, L. 5M
(b). write a function called delete_last() to delete the last element from the given
Single Linked List, L. 5M

9. Show the result of inserting 3, 1, 4, 6, 9, 2, 5, 7 into an initially empty binary tree.

10. Write a program to read an input digit number. Now break this number into individual
digits and then store every single digit in a separate node thereby forming a linked list. For
Example if you enter 12345,then there will 5 nodes in the list containing nodes with values
1,2,3,4,5.

11. Write a program to create a linked list which stores the details of employees in a
department and display the record of an employee having highest pay.

12. Given a linked list that contains English alphabet. The characters may be in uppercase
or in lowercase. Create 2 linked lists – one which stores upper case characters and the other
that stores lower case characters.

13. Write a function call copy stack that copy contains of one stack into another the
program passes two stacks the source stack and the destination stack. The order of the stack
must be identical.

14. Given stack have positive and negative integers, denoting different types of
parentheses. The positive numbers xi denotes opening parentheses of type +x and negative
number –x denotes closing parentheses of type xi.
Open parentheses must be closed by the same type of parentheses. Open parentheses must be
closed in the correct order, i.e., never close an open pair before its inner pair is closed (if it
has an inner pair). Thus, [1,2,−2,−1]is balanced, while [1,2,−1,−2] is not balanced.
You have to find out the length of the longest sub array that is balanced.
Input: 5
1 -1 2 3 -2
Output: 2
Explanation
The longest sub array that is balanced is (1,−1) (2,3,−2) is not balanced as (3) is not balanced.
15. (a). write a function compare() that compares 2 stacks and returns 0 if they are equal?
6M
b). Consider the initial and final states of a stack as shown below: 4M
INITIAL : 10, 9, 27, 4, 29, ---, ---, ---
FINAL : 10, 7, 8, 4, 36, ---, ---, ---.
Write the series of PUSH and POP operations that will transform the STACK from its initial
state to final state.

16. Using only the basic operations of Queue data structure , write a function called
copyqueue() that copies the contents of one queue to another.

17. An automobile dealership shop keeps track of the serial number of its automobiles.
Implement a Linear Queue data structure that supports both insert and delete operations and a
third operation COUNT that gives total number of automobiles.

18. Given a queue of integers implement a program that deletes all negative integers without
changing the order of the remaining elements in the queue.

You might also like