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.

Description:
Declare a structure having the following data types within it.
1. an integer
2. a character
3. an array of integers
4. a string
5. an integer pointer.
6. a character pointer
your declaration may look like this

struct assignment6{
int num;//initialize to 0. This field will be used as a check for the instance being filled or empty.
character ch;
int num_array[10];//initilize to 0
char name[30];
int* int_ptr;
char* char_ptr;
};
Using typedef  change the type " struct assignment6" to assign6
Now create five instances of type " assign6" and for each of the instances do the following.
The sorted arrays and reversed strings should be printed for all the instances should be printed.

Sample output

message printed: Enter the instance number you want to modify. Enter 9 to quit
user enters:  2

The instance number 2 is currently empty.

message printed: Enter the entry number 1 for the array:
user enters: 32
message printed: Enter the entry number 2 for the array:
user enters: -2
message printed: Enter the entry number 3 for the array:
user enters: 1
message printed: Enter the entry number 4 for the array:
user enters: 2
message printed: Enter the entry number 5 for the array:
user enters: 3
message printed: Enter the entry number 6 for the array:
user enters: 4
message printed: Enter the entry number 7 for the array:
user enters: 100
message printed: Enter the entry number 8 for the array:
user enters: 999
message printed: Enter the entry number 9 for the array:
user enters: 10
message printed: Enter the entry number 9 for the array:
user enters: -100

message printed:Enter a string :
user enters: Raja

message printed: Enter the instance number you want to modify. Enter 9 to quit
user enters:  4

The instance number 4 is currently empty.

message printed: Enter the entry number 1 for the array:
user enters: 10
message printed: Enter the entry number 2 for the array:
user enters: 9
message printed: Enter the entry number 3 for the array:
user enters: 8
message printed: Enter the entry number 4 for the array:
user enters: 7
message printed: Enter the entry number 5 for the array:
user enters: 6
message printed: Enter the entry number 6 for the array:
user enters: 5
message printed: Enter the entry number 7 for the array:
user enters: 4
message printed: Enter the entry number 8 for the array:
user enters: 3
message printed: Enter the entry number 9 for the array:
user enters: 2
message printed: Enter the entry number 9 for the array:
user enters: 1

message printed:Enter a string :
user enters: Iqbal

message printed: Enter the instance number you want to modify. Enter 9 to quit
user enters:  2

message printed: The instance is not empty. Please try again.

message printed:
Enter the instance number you want to modify. Enter 9 to quit
user enters:  9

Instance 1
The instance is empty.

Instance 2
The sorted array is  -100 -2  1  2  3  4  10  32  100  999
The reserves string is "ajaR".
The fifth element of the integer array is located at xxxxxxx (xxxxxx represents the address of the memory location).
The fifth element of the string is located at xxxxxxxx

Instance 3
The sorted array is  1  2  3  4  5 6 7 8 9 10
The reserved string is "labqI".
The fifth element of the integer array is located at xxxxxxx (xxxxxx represents the address of the memory location).
The fifth element of the string is located at xxxxxxxx

Instance 4
The instance is empty.

Instance 5
The instance is empty.


Deliverables:
(1) Send the completed source code to the olympus grades account cop32233@olympus1.ir.ucf.edu. Due date for this assignment is
Saturday Nov 12, 2001.