// ***************************************************************** // Author: Zhixiang Chen // Class: CSCI/CMPE 1170, Spring 2009 // Lab 28: Header file for Lab 28 // Date: January 12, 2009 // Comment: The code here is meant to be revised. // ***************************************************************** #include #include #include #include using namespace std; #ifndef LAB_28_HEAD_H #define LAB_28_HEAD_H //this function reverse a char string via pointer operations char * reverse(char * s ) { char *p, *q, tmp; int n; n=strlen(s); //get the length of string s q = (n > 0)? s + n - 1 : s; //see what this do? //p starts at the beginning and move to right //q starts at the end and move to left for (p = s; p < q; ++p, --q) { //swap the char pointed by p with the char pointed by q tmp = *p; *p = *q; *q = tmp; } return s; } //define studentType structure struct studentType { string firstName, //firstnames for students lastName; //last names for students char grade; //letter grades }; //swapOne takes two pointer type parameters void swapOne(int * x, int * y) { //watch carefully how we do the swaping. Compare this with swapTwo int temp; temp = *x; *x = *y; *y = temp; } //swapTwo takes two reference type parameters void swapTwo(int & x, int & y) { //watch carefully how we do the swaping. Compare this with swapOne int temp; temp = x; x = y; y = temp; } //swapOne takes two pointer type parameters void swapThree(int x, int y) { //watch carefully how we do the swaping int temp; temp = x; x = y; y = temp; } #endif