- Aug. 4: Fibonacci Series, Arithmetic Progression and Geometric Progression
- Aug. 11: Finding mode of sorted numbers
- Aug. 18: String length, copy, concatenation using arrays
- Aug. 25: String comparison using arrays, itob (K&R)
- Sep. 1: First occurrence of given character in the given string
- Sep. 8: Recursive functions for itoa, arithmetic and geometric progressions
- Sep. 15: Bit operations: Set bit of a position, Invert bit in the given position, set n bits of x to the bits of y starting from position p (other bits may be changed)
- Sep. 22: Finding the position of substring within the given string using pointers
- Sep. 29: The following two problems need to be done:
Both these problems need to be implemented using pointers only.
- Write a function that takes an integer array as an input and returns the minimum and maximum values in this array as output. Assume that the integers are all positive integers and the maximum value found in the array is 32678. The algorithm MUST find both minimum and maximum in one pass over the array. You should not write the logic twice - once to find minimum and another to find maximum.
- Given two sorted integer arrays, merge them into another sorted array that contains the merged list of integers. For this problem, the integers can be both positive and negative. If a number is duplicated in the input arrays, it MUST occur only once in the output array. In other words, the duplicates are deleted when merging the arrays.
The example test files used for testing are:
msort1.txt,
msort2.txt,
msort3.txt,
msort4.txt,
msort5.txt,
The first line is the number of elements in the first array followed by the elements, then the no. of elements in the second array followed by the elements in the second array. Use them with input redirection with your executable file.
- Oct. 6: Implement the selection sort algorithm. Read the integers to be sorted from a file using fscanf() and store them into an array. This must be a function which returns the number of elements in the array as the return value. Make sure that you DO NOT read more elements than the maximum that can be held by your array. Then, pass this array to the function sort(). Finally, pass the sorted array to the function that writes the sorted values to an output file. The names of the input and output files are to be taken as command line arguments.
- Oct. 13: The program is given a set of integers and a value to be searched in the set of integers. The integers are to be read from a file. The locations where the given value occurs are to be stored in a separate array. These locations need to be written to an output file. The names of the input and output files as well as the value to search are given as command line arguments. Make sure all boundary cases are taken care of and exceptions handled.
As an example, if the file contains the list 10,23,32,46,23,57,78,65,23,43,89,12 and the value to search for is 23, then the locations in which it occurs are 2, 5 and 9. These locations are stored in a location array and written to the output file.
- Oct. 20: Student attendance problem
Problem Definition: Read the monthly attendance of students and calculate the overall percentage of attendance for each student. Then, print the students who have less than 75% attendance.
Input Specification: A file name containing the attendance information is given as a command line argument. The name of the output file that must contain the list of students having less than 75% attendance is also a command line argument.
The format of the input file containing attendance information:
1st line: Number of months of data
2nd line: Number of hours taught/month separated by a space
3rd line onwards: each line will contain the information of a student and is as follows:
reg.no. name att1 att2 att3...attn
where att1, att2 etc. are the number of hours attended by the student for that month. The number of such columns is the number of months for which data is given (obtained from the 1st line of the file).
Output Specification:
reg.no. name %attendance
The number of lines in the output file are the number of students having less than 75% attendance.
How to Program:
The main program should look as follows:
int main(int argc, char **argv)
{
read the attendance data from the file and return total number of hours taughtwith the student data as an output parameter.
calculate the overall percentage for each student and store it.
Write the output to the output file.
}
An example input file:
4
12 10 15 11
14MCME02 Lohit 12 9 12 11
14MCME10 Sravanthi 12 5 10 8
14MCME11 Prashanth 12 6 10 5
- Oct. 27: MINOR
- Oct. 31: Debugging assignment
In this lab, the requirement is to find all the bugs in the code of the following program and fix them. It is important to first design test cases and test the code to understand what the bugs are. Then, it is necessary to reason about why the bug is caused and then fix it.
The three programs are:
- Circular queue program for which the input is given.
- My version of grep command
- A set implementation with the corresponding set.h file. The set implementation has some bugs. Using these, you need to write a main function that uses these functions, find the bugs and fix them. This is not necessary for submission but is useful for more practice on fixing bugs.
- Nov. 3: Dynamic memory allocation problem
Problem Definition: In this class, you have to maintain the frequency of words found in the given input file and write the word and its frequency to the output file.
Maintain a structure of the following form for the words and their frequency:
struct word_freq {
char *word;
int freq;
};
Use fscanf to read one word at a time. Compare it to the stored words. If it is found, increment frequency; otherwise, add the word and initialize the frequency. fscanf should use a string variable. Whenever, the word is not found in the stored words, it should allocate memory for the word using malloc(). The size for malloc() is based on the length of the word returned by fscanf(). The word is copied from the fscanf() variable to the newly allocated memory. Once end of file is reached, write the words and frequency to the output file.
Input: The names of the input and output files are taken as command line arguments
Extra credit: If the line numbers where the word has occurred in the file are maintained and also written to the output file, extra credit of 5 marks will be given. However, for this, you will need to use fgets in a very intelligent way.
Winter Vacation Extension: Accept a wildcard as input for filenames such as "*.txt". You will need to use opendir() and readdir() calls for this. Anyone interested in doing this may contact me for further help after your major exams are over.