Final 12 October 2014, answers PDF

Title Final 12 October 2014, answers
Course Computer Organisation And Programming
Institution Monash University
Pages 13
File Size 557.7 KB
File Type PDF
Total Downloads 835
Total Views 926

Summary

Office Use OnlyMonash UniversitySemester One Examination Period2014Faculty Of EngineeringEXAM CODES: ECETITLE OF PAPER: COMPUTER ORGANISATION AND PROGRAMMINGEXAM DURATION: 3 hours writing timeREADING TIME: 10 minutesTHIS PAPER IS FOR STUDENTS STUDYING AT:( tick where applica ble) ! Berwick &quot...


Description

Office Use Only

Monash University Semester One Examination Period 2014 Faculty Of Engineering EXAM CODES:

ECE2071

TITLE OF PAPER:

COMPUTER ORGANISATION AND PROGRAMMING

EXAM DURATION:

3 hours writing time

READING TIME:

10 minutes

THIS PAPER IS FOR STUDENTS STUDYING AT:( tick where applicable) ! Berwick " Clayton " Malaysia ! Off Campus Learning ! Open Learning ! Caulfield ! Gippsland ! Peninsula ! Enhancement Studies ! Sth Africa ! Pharmacy ! Other (specify) During an exam, you must not have in your possession, a book, notes, paper, calculator, pencil case, mobile phone or other material/item which has not been authorised for the exam or specifically permitted as noted below. Any material or item on your desk, chair or person will be deemed to be in your possession. You are reminded that possession of unauthorised materials in an exam is a discipline offence under Monash Statute 4.1. 1. Attempt ALL questions. Candidates are asked to answer all questions in the spaces provided in the examination paper. This paper consists of 5 questions. 2. Exam paper is printed on single sided paper. Therefore, use the reverse side of any of these pages as scrap paper for any working or calculations that are required in deriving your answers. THESE WORKINGS HOWEVER WILL NOT CARRY ANY MARKS TOWARDS YOUR FINAL ANSWERS. 3. The last two pages contain tables related to MIPS microprocessor which you may find useful in answering these questions AUTHORISED MATERIALS CALCULATORS OPEN BOOK SPECIFICALLY PERMITTED ITEMS Q1

Q2

Q3

! YES ! YES ! YES Q4

" NO " NO " NO Q5

Total Marks

Candidates must complete this section if required to write answers within this paper STUDENT ID __ __

__ __ __ __ __ __ __ __

DESK NUMBER

__ __

QUESTION 1

(20 marks)

Q1.1 (7 marks) In the following C program, the value of x depends on the scope rules. Give the result of each printf() statement in the “Your Answer” column. Your Answer #include void func1(int m); void func2(); int func3(); void func4(int *n); int m = 10; int main(){ func1(20); printf("A %d\n",m); int m; m = func3(); printf("B %d\n",m); func4(&m); printf("C %d\n",m);

A 13

B8 C 38

return 0; } void func1(int m){ printf("D %d\n",m); func2(); }

D 20

void func2(){ int n; for (n=0;nolder); printf(" * %s - %d * ",myptr->name,myptr->age); //printf(" * %d * ",myptr->age); inorder(myptr->younger); } } int main(){ int check=1; char temp_name[100]; int temp_age; FAMILY *ptr=NULL; printf("Creating family tree...\n"); printf("***********************\n"); while (check){ printf("Please insert name: "); scanf("%s",temp_name); printf("Please insert age: "); scanf("%d", &temp_age); insert_node(&ptr, temp_name, temp_age); printf("Any more family members? Y/N(1/0): "); scanf("%d",&check); } inorder(ptr); return 0; }

Write the insert_node function such that the first member of the family will be the root node and all subsequent members will be inserted into the tree following their ages, whereby the younger members will be pointed to by struct family *younger and the older members will be pointed to by struct family *older. Your Answer: void%insert_node(FAMILY%**myptr,%char%*temp_name,%int%temp_age){% % if%(*myptr%==%NULL){% % % *myptr%=%(FAMILY%*)%malloc%(sizeof(FAMILY));% % % % if(*myptr%!=NULL){% % % % (*myptr)F>name%=%(char%*)%malloc(strlen(temp_name)+1);% % % % strcpy((*myptr)F>name,temp_name);% % % % (*myptr)F>age%=%temp_age;% % % % (*myptr)F>older=NULL;% % % % (*myptr)F>younger=NULL;% % % }% % % else%printf("Data%was%not%inserted.%No%memory%available!\n");% % }% % else%{% % % if%(temp_age%age){% % % % insert_node(&((*myptr)F>younger),temp_name,temp_age);% % % }% % % else%{% % % % insert_node(&((*myptr)F>older),temp_name,temp_age);% % % }% % }% % }%

QUESTION 2

(20marks)

Consider the following program: #include #include #include #define SIZE 50 void insert_name(char **list, char *name, int *size); void print_list(char **list, int size); void save_list(FILE *fp, char **list, int size); int main(){ FILE *fp; char *name[SIZE]; char temp[30]; int size = 0, choice = 0; do{ printf("MENU:\n1: To insert a name\n"); printf("2: To print all names in the list\n"); printf("3: Load a list\n"); printf("4: Save the list\n"); printf("5: Exit Program\n"); printf("Your choice: "); scanf("%d",&choice); if (choice == 1) { if (size...


Similar Free PDFs