Assignment - 1

Problem Definition: Find the given string in the given input text.

TO DO: Come up with questions that will disambiguate the above problem definition and lead to the specification.


Assignment - 2

Problem Definition: Given the monthly attendance information of students, find the list of students who have less than 75% attendance.

TO DO: Come up with questions that will lead to a specification for the problem above.


Assignment - 3

Problem Specification: Given the number of terms to generate, the initial term and the common difference or ratio, generate the terms of Arithmetic and Geometric progressions respectively. If the number of terms is less than or equal to 0, print the error "Number of terms must be a positive integer". Print the message "Arithmetic Progression of N terms with initial term X and common difference D is as follows" and then print the terms on the next line. Finally, print a new line. Replace "Arithmetic" by "Geometric" and "difference" by "ratio" in the above for geometric progression. N, X and D must be the values input by the user (DO NOT PRINT N, X, D/R - print the actual values).

TO DO: Develop the algorithm for the above problems.


Assignment - 4

Write an algorithm that determines the mode of a list of numbers. The mode is the value that occurred most frequently. For example, in

1 2 2 3 3 3 4 5 5 6 6 7 7 7 7 8

the mode is 7 with a frequency of 4. You may assume that:

  1. The values are already sorted into ascending sequence.
  2. The values are input to the algorithm from the keyboard. When a value of -1 is encountered, print the mode and exit the program.
  3. If two or more values occur with equal frequency, the mode is the numerically defined largest value.
The algorithm you develop SHOULD NOT all the data in a list; it should read in only one value at a time and process that value. The output of your algorithm should be the mode and its frequency.


Assignment - 5

Will be implemented in the lab on Aug. 25th. The algorithm is DUE ON 23 Aug. 2015.

Input: A file name which contains the list of numbers to be sorted and another file in which to store the sorted numbers.

Format of the data in the files: The data in the files is just a series of numbers separated by a single space.

TODO: Read a list of numbers from a file whose name is given by the user until the end of the file is reached and store them into an array. Then, sort the numbers in the ascending order. If two numbers have the same value, they are in successive locations, i.e., duplicates are allowed.

The algorithm to use is the following:

Go through the list of numbers in the array and find the smallest element. Exchange it with the first element and so on until all numbers are done. This is called the insertion sort algorithm.

NOTE: Use the top-down design approach. The basic outline of the main function will be as follows:

Step 1: read data from the file and store into an array of numbers

Step 2: Sort the data into ascending order.

Step 3: Print the sorted numbers into the output file.

Each of the above can be written as a function and tested independently before testing the entire program. This is a good example of how modularity helps to bring all the logically connected statements into small functions that can be independently tested.

Output: Print the sorted list of numbers to the file whose name is given as input.


Assignment - 6

This is the lab assignment for Aug. 18th. In this lab, you will be accepting an operation to be performed on strings from the user and one or two strings depending on the operation to be performed on them. The operation can be either finding the length of the string, string copy or string concatenation. Remember that in C, a string is an array of characters that ends in a NULL character (i.e., '\0'). You need to write the three operations as functions with the following prototypes:

int strlen(char s1[]);

void strcpy(char s1[], char s2[]);

void strcat(char s1[], char s2[]);

The maximum length of any string entered by the user is 15.

In strcpy and strcat, the string s1 is the destination string, i.e., in strcat, it is both the input and output string. If I give the strings as "hello" and "world", the output of strcat will be "helloworld" in string s1. For strcpy, if I give the string "kernighan", this becomes the string s2 and when I print s1 after returning from strcpy, it should contain the string "kernighan".

OUTPUT: Print the string length if that is the operation chosen or the string s1 if it is either strcpy or strcat. This printing must be done in the main function after returning from the function calls.