You are on page 1of 2

Assignments of Introduction to Programming - 2011

Introduction to Programming - 2011


Assignments
1. Write a program that accepts three integers x, y, and z, and prints the value of (x+y), (x-y), (2x+3), (y2/z), (y/z) and (x/(y+z)). The program should warn if the denominator for division is zero and should exit the program with informative error. Demonstrate a program that can do the following tasks: i. Swap two numbers without using a third variable ii. Find factorial of a number iii. Multiply two numbers without using '*' iv. Print first n (n>2) Fibonacci (Fib) numbers using only three variables (Definition of Fib: Fib(i)=Fib(i-1)+Fib(i-2); Fib(0)=0 and Fib(1)=1) v. Using simple loops and without using inbuilt functions or math.h, find the number of bytes allocated by the compiler for: a. short int b. int c. long int Demonstrate program that reads vectors A and B and computes C: i. C = A - 2B ii. C = 5A . B iii. C=AxB Use 2-d matrices to represent matrices. i. Find if the 2-D arrays are being stored in row-major or column-major order using: a. values stored b. debugger ii. Transpose a matrix reading values as strings and then converting them to integers iii. Implement addition of matrices of dimension n x n iv. Implement multiplication of matrices of dimension n x p and p x n v. Convert any element aij of an integer matrix A to a string and print its length Demonstrate functions that: i. Concatenates two strings ii. Count the number of vowels in a string iii. Finds if one string is a substring of another iv. Change upper-case letters to lower case v. Display ASCII code of the characters vi. Replace an alphabet with the next alphabet (eg: a with b, g with h and z with a) vii. Implement 5(i)-5(v) using a header file viii. Implement 5(i)-5(v) using a header file for declaration and a library for definition Demonstrate separate pointer-based functions that: i. swap two numbers ii. returns dot product of two vectors (represented by arrays) iii. find if a 2d array is stored in row-major order iv. find the memory locations and values of all the variables (including pointers) used in the main() and in the calling functions used in 6(i) & 6(ii) v. product of two rectangular matrices

2.

3.

4.

5.

6.

P a g e |1

Assignments of Introduction to Programming - 2011

7.

Using separate functions show: i. Access directly a value in an array for given the indices i, j without using A[i][j] but using the information from 4(iii) ii. Using pointer to functions, show how identical statement can be used to do different tasks Demonstrate: i. For a structure S that has two real number members x and y of which A, B and C are instances, functions that: a. Add corresponding elements of structure S where the structure are two real numbers x and y (as if C=A+B and S is a 2x1 matrix) b. Subtract the corresponding elements of the first with the second (C=A-B) c. Multiple the corresponding elements of the first with the second (C.x=A.x * B.x and C.y=A.y * B.y) ii. For a union U with variables of type int, float and a string of size 10 with instances I, F and S, that they can be used for completely different purposes which are data type dependent iii. Demonstrate various bitwise operations Write a function that for a given filename: i. Prints the contents of the file ii. Creates a file with content being its file name iii. Appends into the file its file name iv. Prints directly some content in a binary file

8.

9.

10. Write a program that uses set of programs (also to be written) as given below, which, when compiled together, work to serve various tasks. No extra functions should be used. i. fact.cpp: a function that gives the factorial of an integer ii. pi_fib.cpp: a function that gives pi times Fibonacci number iii. head.h: a header file with value defined for pi to 6 decimal places and a declaration mean that returns the average of two numbers iv. Outputs "Identical" if two files, named through command line, are identical 11. Demonstrate a function that: i. Inserts a given number into a linked list such that all numbers in the list remain sorted. Assume that the list, if not empty, is initially sorted. ii. For a structure that has two elements that are numbers, write a function that can traverse a doubly linked list in either direction.

P a g e |2

You might also like