COMP ENG 2SH4 Principles of Programming Day Class Duration of Examination: 2.5 Hours MCMASTER UNIVERSITY FINAL EXAMINATION
COMP ENG 2SH4 Principles of Programming Day Class Duration of Examination: 2.5 Hours MCMASTER UNIVERSITY FINAL EXAMINATION Instructor: SORINA DUMITRESCU December 2016 This examination paper includes 5 pages and 5 questions. You are responsible for ensuring that your copy of the paper is complete. Bring any discrepancy to the attention of your invigilator. SPECIAL INSTRUCTIONS: Do not detach pages from this exam. Answer all questions on the provided answer booklet. This paper must be returned with your answers. The number in brackets at the start of each question is the number of points the question is worth. No reference material of any kind is allowed. No calculators of any kind are permitted. 1. (20) Q1. Programming in C: Write a C function with prototype int isSuffix(const char* s1, const char* s2), which returns 1 if string s1 is a suffix of string s2 and returns 0 otherwise. Note that string s1 is a suffix of string s2 if s1 appears at the end of s2. Examples: ”end” is a suffix of ”weekend”; ”end” is a suffix of ”end”; ”week”, ”eke” and ”back” are not suffixes of ”weekend”. If you need to use any function in your code, you will have to write it yourself. For instance, you may write a function which returns the length of a string, and use it in function isSuffix(). You are not allowed to use any C library functions. Include instructive comments. Solution 1: int len(const char *s){ int i=0; while(*s!=0){ i++; s++; } return i; }// end len int isSuffix(const char* s1, const char* s2){ int l1=len(s1), l2=len(s2); if(l1l2) return 0; for(i=0; il1; i++){ if(s1[l1-1-i]!=s2[l2-1-i]) return 0; } return 1; } 2. (20) Q2. Programming in C: This exercise uses the following C structure type definition: typedef struct{ int day; int month; int year; } Date; Write a C function with prototype int remove(Date* birthdates[], int* sizePtr, int index), where birthdates is an array of pointers to structure variables of type Date, each such structure variable representing the date of birth of an employee in a company. You may think of the array birthdates as a list containing all these birth dates. Parameter sizePtr is a pointer to a variable in the caller that stores the size of the list (number of structure variables). Function remove() is invoked to remove from the list the date of birth of an employee who leaves the company. Parameter index represents the position in the array c
Geschreven voor
- Instelling
- COMP ENG 2SH4
- Vak
- COMP ENG 2SH4
Documentinformatie
- Geüpload op
- 23 oktober 2023
- Aantal pagina's
- 10
- Geschreven in
- 2023/2024
- Type
- Tentamen (uitwerkingen)
- Bevat
- Vragen en antwoorden
Onderwerpen
-
comp eng 2sh4 principles of programming day class