CSE101
FOUNDATIONS OF COMPUTING
HOMEWORK # 3
Part-A
1. Define a structure called cricket that will describe following information:
player name
team name
batting average
Using cricket, declare an array of structures ‘player’ with 10 elements and write a program to read the information about all the 10 players and print a team-wise list containing names of players with their batting average.
2. Define a structure that describes a hotel. Its members must be name, address, grade, average room charge and number of rooms. Write functions to perform following operations:
- To print out hotels of a given grade in order of charges.
- To print out hotels with room charges less than given value.
- To update the room charges of all the grades of the hotel.
(Pass the whole structure as an argument of the function to view the new charges.)
3. Write a program to create a data type time and demonstrate the difference between union and structure, if time is designed using union or structure.
Part-B
4. Write a program to create an n-dimensional array on the runtime with the help of pointers. Use dynamic memory allocation functions to allocate and deallocate the memory at the end.
[For example, if user enters 2 as a dimension input, a 2D array will be generated with the number of elements entered by the user until the enter key is pressed.]
5. Write a program to create a string (a char array) and find the length of that string with the help of a pointer, not any in-built function. Also display the string in the reverse order using the pointer element.
6. Write a function (using pointer parameters) that compares two integer arrays to see whether they are identical. The function returns 1 if they are identical, 0 otherwise.