Programming Assignment number 6
Note: If you feel the directions are not clear enough please send
me a mail or stop by my office clearly specifying what need to be done to
make everything understood better.
Here are a few questions sent to me by a student about the assignment. I
am replying to the questions and posting them.
/**********************************************/
1. int num;//initialize to 0. This field will be used as a check for the instance
being filled or empty.
and also :
Store the instance number in the num field of the structure. For example if the
instance number is 3. Set num=3;
does you mean we should initialize the num to 0 for all instances. And when
the user chooses to use an instance , we set the NUM to the value?
This is exaclty what I meant. First the instance has to be created and then the appropriate
members of each of the instances has to be initialized. For example the num will be initialized to
0. You can have a function that takes the pointer to the instance and initializes all the values
to the appropriate intial values.
2. you say fill the character fieled with letter A..E consequently. Does that
have to be done in initialization? or when the user enters the data?
Do it when the user inputs the data and not during the intialization.
3. When displaying the Instances , why do u not display the contents of the
character field?
That was a mistake. I would like the character field to be displayed. If someone has not displayed it
I wont take off any points for that.
4. When we enter a string, does you want us to reverse it or just display the
reverse?
You have to write a separate function that actually reverses the string and does not just display the
reversed string.
5. When we enter the numbers to the array, should we sort the array, or just
on the display we do that?
You have to actually sort the array. You can use the array sorting function used in one of the previous
homework assignments for this.
6.In case we do sort and reverse in array and string, do we use int_ptr and
char_ptr to point to the fifh element of the array and string to point to the
sorted element or before sorting and reversing.
This will be the same in both cases, whether you do it before or after sorting.The pointers point to the fifth
location and whatever value is there, this wont make any difference.
7. When user enters an instance number and that instance is already FILLED
and entered, do we allow him to enter it again or we say it is not empty and that
is all?
Yes.... If the instance is already filled. Do not allow the user to enter the values.
8. what would happen if the user enters a string that is less than 5
characters and we have to point to the 5th element? I mean i know we can anyways
display the memory loction , but just asking in case.
Good question!!!!! Think about it for a while. Although there is no valid data on the fifth location, still there
will be some junk on that location. I want the address of the fifth location, whether it is valid data or garbage.
It wont make any difference
Please let me know if you have more questions.
/*************************************************/
Objectives: To understand the use of structures.
Restrictions:
Use the gcc compiler and text editor emacs/pico/pine for your assignment.
Your source file shall begin with comments containing the
following information:
/* Name:
Course:
Section:
Assignment title:
Date:
*/
Use sufficient comments to provide information about your code.