Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Data Structure Expert

Question 1

(a) Explain the meaning of each of the following pointer declarations:-

(i) float a = -0.137;

float *pa = &a;

(ii) double *fa(double *a, double *b, double *c);

(iii) char *d[4] = {"north", "south", "east", "west"};

(iv) int (*pf)(char *a, char *b);

(b) Read the structured program below and answer the questions based on it

int i, j = 25;

int *pi, *pj = &j;

*pj = j + 5;

i = *pj + 5;

pi = pj;

*pi = i + j;

Assume each integer quantity occupies 2 bytes of memory, the hexadecimal address of i begins at F9E and that of j at FA0

(i) What value is represented by &i?

(ii) What value is represented by &j?

(iii) What value is assigned to pj?

(iv) What value is assigned to *pj?

(v) What value is assigned to i?

(vi) What value is represented by pi?

(vii) What final value is assigned to *pi?

(viii) What value is represented by (pi + 2)?

(ix) What value is represented by the expression (*pi + 2)?

(x) What value is represented by the expression *(pi + 2)?

(c) Write an appropriate declaration for each of the following situations involving pointers

(i) Declare a function that accepts an argument which is a pointer to an integer quantity and returns a pointer to a six-element character array

(ii) Declare a function that accepts an argument which is a pointer to an integer array and returns a character

(iii) Declare a function that accepts an argument which is an array of pointers to integer quantities and returns a character

(iv) Declare a function that accepts an argument which is an integer array and returns a pointer to a character

(d)(i) What is the purpose of the buffer area when working with a stream oriented data file?

(ii) How is the buffer area defined? Illustrate your answer with the appropriate sample code

(iii) What is the purpose of the fclose function? Is it necessary within a program using a data file?

(e) Write the sample code to open a data file called 'inputfile.txt' in read only mode and to check whether the file is correctly opened

Question 2

(a) How does a structure differ from an array? Illustrate your answer with simple examples

(b) Explain how a structure differs from a union? Illustrate your answer with simple examples

(c) Write the sample code to declare a union named 'clothes'. The union has two variables 'shirt' and 'blouse' and its members are-

1. manufacturer of type character and size 20

2. cost of type float

3. size of type character (e.g:- S - small, M - medium, L - large and XLextra large)

(d) Explain what is a 'nested structure'. Illustrate your answer with a suitable example

(e) (i) Define a structure consisting of two floating point members called real and imaginary. Include a tag called complex within the definition

(ii) Declare three variables x1, x2 and x3 of be structures of type complex

(iii) Assign the initial values of 1.3 and -2.2 to the members x.real and x.imaginary, respectively

(iv) Declare a pointer variable px to point to a structure of type complex

(v) Declare a one-dimensional 100-element array called cx whose elements are structures of type complex

(vi) Combine the structure definition and the array declaration of part (v) into one single declaration

(f) (i) Define a union called 'dateTime' which contains three members: hour, minute and second

(ii) Define a structure called 'calendarDate' which contains three integers members: day, month and year and a member time1 of type dateTime

(iii) Declare a variable date1 of type 'calendarDate'

(iv) Set the time of date1 to: 10:30:25

Question 3

(a)

(i) What is recursion?

(ii) What advantage is there in its use?

(iii) What disadvantage is there in its use?

(b) The factorial of a positive number can be computed using the formula

n ! = 1 x 2 x 3 x..........x n

However, the function „factorial? can also be defined as a recursive function in programming exercises

Write down the main part of the program which contains the following-

(i) the function prototype

(ii) a positive integer variable n

(iii) an output statement to display n

(iv) an input statement to allow a user to enter a number (which is stored in variable n)

(v) another output statement that calculates and displays the factorial of the number

(vi) write down the function using recursion

(c) (i) Explain why a linked list is called a dynamic data structure?

(ii) What are the three most important advantages of using linked list over arrays?

(iii) State one disadvantage of using linked list in structured programs

(d) A stack is also a dynamic data structure which can be implemented in its simplest way by making use of arrays

Declare a structure containing:-

(i) an integer array to hold the elements of the stack

(ii) an integer to indicate the position of the current stack top within the array. Now write the „pop? operation to remove the top element from the stack. Write the "push? operation to add an element to the stack

Question 4

(a) One of the most common sorting techniques we have in programming is the "Bubble Sort?. This technique can be used to sort an array of elements in ascending order

Write down the sample code which will rearrange a list of numbers stored in an array in ascending order using the Bubble Sort

(b) (i) What do you understand by „linear search?? Illustrate with a simple algorithm of your own

(ii) Explain how the „binary search? differs from the „linear search?? Use a simple algorithm of the binary search to illustrate your answer

(c) (i) Explain the FIFO structure of the queue

(ii) Explain how you would implement the queue data structure in its simplest form. Illustrate your answer fully with the necessary sample code

Data Structure, Computer Science

  • Category:- Data Structure
  • Reference No.:- M9134059

Have any Question?


Related Questions in Data Structure

Problem regarding the management program

Problem: Looks like its just adding a save and load feature to the same file you sent me for python 3.5 Until now, you have had to leave your team management program running on your computer indefinitely since you did no ...

Data Communication Delivering Information anywhere

Topic: Data Communication Delivering Information anywhere. Write a 9-12 pages paper in which you: Present an overview of the origin and history of the concept. Describe the current use of and attitude toward the concept. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As