• Study Resource
• Explore

Survey

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Transcript
```El-Shourouk Academy
Higher Institute for Computer &
Information Technology
Department of Computer Science
Term
: First
Year
: Second
2102 Data Structures
Sheet # 4-Structures
Exercise 4-1.
(a) – Define a structure called record which holds an integer called loop, a character
array of 5 elements called word and a float called sum.
(b) – Declare an object called sample, defined from a structure of type record.
(c) – Assign the value 10 to the field loop of the sample object of the type record.
(d) – Print out the value of the word array of the sample object.
(e) – Define a new structure called birthdays, whose fields are a structure of type time
called btime, and a structure of type date called bdate.
Exercise 4-2. True/False:
(1) – The structure dot operator (.) is used to access members of a structure via the
structure name.
(2) – Structures are collections of related variables under one name. They may contain
variables of many different types.
(3) – Arrays are dynamic, so the length of an array can increase or decrease as
necessary. An array is appropriate when the number of data elements to be represented
in the data structure is unpredictable.
(4) - A structure cannot contain an instance of itself.
(5) - When structures or individual structure members are passed to a method, they are
passed by reference.
Exercise 4-3.
When working with structures, a field that is not explicitly set through a ‘new’ statement
or through an assignment operator is said to be what?
Exercise 4-4.
Suppose that a real number is represented by a C# structure such as:
struct realtype {
int left;
int right;
}
Where left and right represent the digits to left and right of the decimal point,
respectively. If left is a negative integer, the represented real number is negative.
(a) Write a method to input a real number and create a structure representing that
number.
(b) Write a method that accepts an object of such structure and returns the real
number represented by it.
(c) Write a methods to add, subtract, and multiply that accept two objects of such
structure and set the value of a third object of such structure to represent the
number that is the sum, difference, and product of the two input objects.
1
```
Document related concepts
no text concepts found
Similar