Download presentation
Presentation is loading. Please wait.
1
EECE.2160 ECE Application Programming
Instructors: Dr. Lin Li & Dr. Michael Geiger Spring 2019 Lecture 36: Exam 3 Preview
2
ECE Application Programming: Exam 3 Preview
Lecture outline Announcements/reminders Program 8 due today Program 9 (extra credit) due 5/8 Exam 3: Tue, 5/7, 3-6 PM, Ball 210 Course evals online; will also have hard copies available You’ll submit eval at exam Wed. 5/8: All code due by 11:59 PM Program 9: Worth up to 4 points extra credit on final avg Resubmission deadline for remaining programs Today’s class: exam 3 preview Exam outline Review of material 9/2/2019 ECE Application Programming: Exam 3 Preview
3
ECE Application Programming: Exam 3 Preview
Exam 3 notes Allowed one 8.5” x 11” two-sided note sheet No other notes or electronic devices Exam lasts 3 hours (but written for ~50 min) Coverage All lectures after Exam 2 (lectures 24, 26-35) Format similar to Exams 1 & 2 Code reading, writing, multiple choice questions One 10 point extra credit question at end For this exam, you may attempt the extra credit question even if you haven’t attempted to solve all other problems 9/2/2019 ECE Application Programming: Exam 3 Preview
4
ECE Application Programming: Exam 3 Preview
Exam 3 outline (CR = code reading, CW = code writing, MC = multiple choice) Strings: CR/CW questions on String functions (copy, concatenate, length, compare) Strings as function arguments Structures: CR/CW questions on Basic structure accesses Dot operator (i.e., s1.x) Pointer access (i.e., p->GPA) Arrays of structures Nested structures File input/output: MC questions that may involve fopen()/fclose() Text file I/O using fprintf()/fscanf() Binary file I/O using fread()/fwrite() Standard I/O streams: stdin, stdout 9/2/2019 ECE Application Programming: Exam 3 Preview
5
ECE Application Programming: Exam 3 Preview
Exam 3 outline (CR = code reading, CW = code writing, MC = multiple choice) Character/line I/O: MC questions that may involve fgetc(), getchar(), ungetc() fgets() Extra credit: may focus on any topic above Should clearly understand earlier material, too 9/2/2019 ECE Application Programming: Exam 3 Preview
6
ECE Application Programming: Exam 3 Preview
Review: strings Represented as character arrays Can be initialized using string constants char hello[] = “Hello”; Can access individual elements hello[3] = ‘l’; Can print directly or with formatting Print directly: printf(hello); Print w/formatting using %s: printf(“%s\n”, hello); Reading strings: scanf(“%s”, str); Reads all characters up to (but not including) first space, tab, or newline Must leave enough room for terminating ‘\0’ 9/2/2019 ECE Application Programming: Exam 3 Preview
7
Review: String functions
In <string.h> library: Copying strings: char *strcpy(char *dest, const char *source); char *strncpy(char *dest, const char *source, size_t num); Return dest Does not append ‘\0’ unless length of source < num Comparing strings: int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, size_t num); Character-by-character comparison of character values Returns 0 if s1 == s2, >0 if s1 > s2, <0 if s1 < s2 9/2/2019 ECE Application Programming: Exam 3 Preview
8
Review: String functions (cont.)
Find # of characters in a string size_t strlen(const char *s1); Returns # characters before ‘\0’ Not necessarily size of array “Add” strings together—string concatenation char *strcat(char *dest, const char *source); char *strncat(char *dest, const char *source, size_t num); Returns dest 9/2/2019 ECE Application Programming: Exam 3 Preview
9
ECE Application Programming: Exam 3 Preview
Review: Structures User-defined types; example: typedef struct { char first[50]; char middle; char last[50]; unsigned int ID; double GPA; } StudentInfo; Can define variables of that type Scalar: StudentInfo student1; Array: StudentInfo classList[10]; Pointer: StudentInfo *sPtr; 9/2/2019 ECE Application Programming: Exam 3 Preview
10
Review: structures (continued)
Initialization very similar to array initialization: StudentInfo student1 = { “John”, ‘Q’, “Smith”, , 3.75 }; Access members using Dot operator: student1.middle = ‘J’; Arrow (if pointers): sPtr->GPA = 3.5; Typically passed to functions by address 9/2/2019 ECE Application Programming: Exam 3 Preview
11
Review: Arrays of structures
Initializing structure arrays: studentInfo list[3] = { {"John", 'Q', "Smith", 123, 3.0}, {"Jane", 'A', "Jones", 456, 3.95}, {"Mary", 'X', "Ford", 789, 3.72} }; Access members of structs in arrays—each array element = 1 struct, so use dot operator list[0].GPA = 2.5; strcpy(list[1].first, "Janet"); 9/2/2019 ECE Application Programming: Exam 3 Preview
12
Review: Nested structures
Structures can contain other structures: typedef struct { char first[50]; // First name char middle; // Middle initial char last[50]; // Last name } Name; Name sname; // Student name unsigned int ID; // ID # double GPA; // Grade point } SINew; 9/2/2019 ECE Application Programming: Exam 3 Preview
13
Review: Nested structure accesses
Will need multiple dot operators to access field within nested structure Given SINew s1; s1.sname Name structure within s1 s1.sname.middle middle initial of name within s1 Structure pointer typically only to top-level structure Given SINew *sp = &s1; sp->sname Name structure within s1 sp->sname.middle middle initial of name in s1 9/2/2019 ECE Application Programming: Exam 3 Preview
14
ECE Application Programming: Exam 3 Preview
Review: File I/O Open file: FILE *fopen(filename, file_access) Close file: fclose(file_handle) Formatted I/O: fprintf(file_handle, format_specifier, 0+ variables) fscanf(file_handle, format_specifier, 0+ variables) Unformatted I/O: size_t fwrite(pointer, element size, # elements, file_handle) size_t fread(pointer, element size, # elements, file_handle) 9/2/2019 ECE Application Programming: Exam 3 Preview
15
ECE Application Programming: Exam 3 Preview
Review: Generic I/O Special I/O streams in C stdin: standard input stdout: standard output printf(“Hello\n”) == fprintf(stdout, “Hello\n”); scanf(“%d”, &x) == fscanf(stdin, “%d”, &x); Can write generic code that deals either with specific file or standard input/output 9/2/2019 ECE Application Programming: Exam 3 Preview
16
ECE Application Programming: Exam 3 Preview
Review: End of file Two ways to check for end of file: Text files: Check if fscanf() == EOF More common: do fscanf() as part of loop condition, and continue while EOF not reached e.g. while (fscanf(fp, “%d”, &y) != EOF) Binary files: feof(file_handle); Note: both functions indicate EOF after failed read operation Must try to read data and discover that there’s nothing to read before testing for EOF 9/2/2019 ECE Application Programming: Exam 3 Preview
17
Review: character/line input
Character input int fgetc(FILE *stream); int getchar(); int ungetc(int c, FILE *stream); Line input char *fgets(char *s, int n, FILE *stream); 9/2/2019 ECE Application Programming: Exam 3 Preview
18
ECE Application Programming: Exam 3 Preview
Next time Exam 3: Tuesday, 5/7, 3-6 PM, Ball 210 Don’t forget to complete your course eval before exam! Hard copies available from Dr. Geiger’s office Reminders: Program 8 due today Program 9 (extra credit) due 5/8 Wed. 5/8: All code due by 11:59 PM Program 9: Worth up to 4 points extra credit on final avg Resubmission deadline for remaining programs 9/2/2019 ECE Application Programming: Exam 3 Preview
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.