You are on page 1of 3

Assignment 1

Groups: I & II Due on: 19th March, 2013 Sl. No. 1. 2. 3. Problem Write a program that will place the kth element of an array in position 1, the (k + 1)th element in position 2, etc. The original 1st element is placed at position (n k + 1) and so on. Write a program to represent a matrix in sparse form. A tridiagonal matrix has entries aij that are zero except when | i j | 1, for 1 i, j n. Write a program to implement the above, while ensuring that the non-zero elements of the matrix are stored in (3n-2) consecutive locations, where the dimension of the matrix is n x n. Write a program to implement the following functions for a string: a) Create a string of text. b) Concatenate two strings to form another string. c) Search and replace a given substring within a string. d) Compare a string with another. e) Compute the length of a string. Given a subject string, a pattern string, an initial cursor position, an initially empty matched string, a replacement string, a replacement condition (true or false), the break operation will scan the subject string on a character-bycharacter basis, starting at the given cursor position and proceeding to the first instance of a character which is also a character in the pattern string. If such a character is found, a) The algorithm exits with the value of true b) The matched string argument is assigned the substring of the subject from the initial cursor position up to, but excluding, the character found c) The replacement string replaces the matched string in the subject string if the replacement condition is true d) After a replacement is completed, the cursor value is updated to point at the break character found. e) If a pattern character is not found, the algorithm returns false, and no changes are made. Write a program to implement the above algorithm. Topic: Arrays, Strings and Structures Date: 12th March, 2013 Page # Source File (s) Remarks

4.

5.

Sl. No. 6.

Problem Write a program to read a file and a) Add lines of text after the last line of text in the file b) Delete a line of text from the file. c) Centre-align a line of text in the file. Write a program which will read a piece of text from a file and obtain: a) The number of sentences in the file b) The average number of words in a sentence c) The average number of characters in a word The following assumptions are to be made: a) Each sentence within the text is delimited by a period followed by two blanks and embedded periods are not permitted. b) Each word within a sentence is delimited by one blank space. c) Punctuation symbols are not to be counted as characters. d) Words are not divided from one line to the next and the last word on each line is followed by at least one blank. e) The first word in each line is preceded by blanks only if it is the first word in a paragraph. Write a program for a chain of 20 department stores, each of which sells five different items. Every month, each store manager submits a data card for each item, consisting of a branch number, an item number and a sales figure, representing the amount of sales for that item in that branch. However, as all items are not sold in all branches, some managers may not submit cards for some items. Your program will read these data cards and print a table with 12 columns. The first column will contain the branch numbers from 1 to 20 and the word TOTAL in the last line. The next ten columns will contain the sales figures for each of the ten items for each of the branches, with the total sales of each item in the last line. The last column will contain the total sales of each of the 20 branches for all the items, with the grand total sales figure for the chain in the lower right-hand corner. Each column should have an appropriate heading. If no sales were reported for a particular branch and item, assume zero sales.

Page #

Source File (s)

Remarks

7.

8.

Sl. No. 9.

Problem A real number is represented by a structure whose members left and right represent the digits to the left and right of the decimal point respectively. Write a program which will a) Input a real number and create a structure representing that number. b) Accept such a structure and return the real number represented by it. c) Add, subtract and multiply two such real numbers. Write a program to implement complex numbers. Your program should be able to add, subtract and negate complex numbers.

Page #

Source File (s)

Remarks

10.

Note: 1) 2) 3) 4) 5) Programs should be written in C syntax only. Programs should be well indented and documented. A sample output must be provided for each program. Programs must take into account all possible test cases. Programs must be modularised and separate source files are to be used for the different modules. 6) Use of the header file <string.h> is prohibited for this assignment. 7) The outputs must be saved in an external file.

Lab. Instructor 3

Faculty

You might also like