cs2010 Midterm 2 Study Guide F18 [Thurs Nov 15] Topics: - C-strings: declaration, initialization, strcpy, strcat, strlen, strcmp - Character testing: cctype isalpha, isdigit, toupper, tolower, etc - accessing individual char values w/in cstring via index op: str[0] - cin >> str; cin.getline(str, MAXLEN); cin.get(str[i]); cin.ignore(); cin.ignore(256, '\n'); - Arrays: declaration, initialization, bounds of an array, implicit arrays, partial arrays, initialization list, 2D arrays - Array traversal - print, linear search, accumulation, etc - Parallel Arrays - relationship between two or more arrays w/ respect to their indexes - Passing arrays as function arguments - Object Oriented Programming Principles part1: Encapsulation, Abstraction - Abstract Data Types: Programmer defined data types - Structures or Classes - Structure Definitions: object instantiation, accessing member variables of an object, array of objects, nested structures "aggregation" - Class Definitions: private and public access specifiers, member variables, accessor and mutator member functions, default constructor, destructor. Member function prototypes declared within class definition and full member function definitions outside the class (ex: returnType ClassName::memberFunction(){...} ) - Pointers: declaration, initialization, *dereferencing, &addresses, pointer and array similarities and differences, nullptr and SEGFAULT, pointer arithmetic, pointer to a variable, an array, an object. -------------------------------------------------------------------------------- #. Write the C++ procedural code for the function my_strlen. This function will pass a constant cstring, count the number of printable characters, and return the integer length of the passed cstring. #. Write the C++ procedural code for the function isPalindrome. This function accepts a constant cstring argument and a constant integer for the cstring's capactiy. This function will test whether the passed cstring is a palindrome and return a boolean true if so, false otherwise. (ex: racecar, kayak) #. Write the C++ procedural code for the void function displayAllEmployees. This function will pass in a constant array of cstrings, two constant double arrays, and a constant integer for the count of employees. This function will traverse the arrays in parallel and output each employee's name, payrate, and hours. #. Write the C++ structure definition for an Employee. The Employee structure definition will contain the following member variables: a cstring for the name, a double for payrate, and an integer for hours. #. (a) Define encapsulation and abstraction. Explain how these concepts relate to classes and object oriented programming. (b) What is a class and what is an object? #. You have a program with four variables: p1, p2, v1, v2. p1 and p2 are integer pointers while v1 and v2 are integer variables. Currently, the variables are stored in memory as shown in the following: Var Name p1 p2 v1 v2 ____ ____ ____ ____ | | | | | Value Stored|0x0 |0x0 | 50 | 40 | |____|____|____|____| Mem Address 0x20 0x24 0x28 0x32 Show how each of the following lines of code would affect the above picture. Each of the lines of code is evaluated in the order presented (ex: before (b) is executed, (a) has occurred). (a) p1 = &v1; (b) p2 = p1; (c) *p2 =99; (d) p2 = &v2; (e) What value would output: cout << p1 << endl; (f) What value would output: cout << *p2 << endl; (g) What value would output: cout << &v1 << endl; #. What is the main difference between classes and structures? #. What does the -> operator and the . operator have in common? How do they differ? #. You have the class Employee with the member variables (cstring [cap:64])name, (int)id, (int)hours, and (float)payrate. (a) write the full default constructor definition that "zeros" out the member variables. (b) write the full displayEmployee definition that will print the object's member variables name, id, hours, and payrate, and calculate and display the employee's paycheck.