Professional Documents
Culture Documents
EXERCISE
4
Pointers
Here, type is the pointer's base type; it must be a valid C++ type and var-name is the
name of the pointer variable. The asterisk you used to declare a pointer is the same asterisk
that you use for multiplication. However, in this statement the asterisk is being used to
designate a variable as a pointer. Following are the valid pointer declaration:
int *ip; // pointer to an integer
double *dp; // pointer to a double
float *fp; // pointer to a float
char *ch // pointer to character
The actual data type of the value of all pointers, whether integer, float, character, or
otherwise, is the same, a long hexadecimal number that represents a memory address. The
only difference between pointers of different data types is the data type of the variable or
constant that the pointer points to.
There are few important operations, which we will do with the pointers very
frequently. (a) we define a pointer variables (b)assign the address of a variable to a pointer
and (c) finally access the value at the address available in the pointer variable. This is done
by using unary operator * that returns the value of the variable located at the address
specified by its operand.
INSTRUCTIONS:
Copy your source codes to be pasted in this document as well as a screen shot of
your running output.
Upload your document using the link provided in your Canvas.
#include <iostream>
using namespace std;
void stringCat(char *s1, char *s2);
int main ()
{
char str1[20]="The Happy";
char str2[20]=" Man";
stringCat(str1,str2);
cout<<str1;
system("pause > 0 ");
return 0;
}
#include <iostream>
using namespace std;
char *stringRev(char *s);
int main ()
{
char str [] = "Happy Day";
cout << stringRev(str);
IV. ASSESSMENT
Topic Pointers
Lab Activity No 4
Lab Activity Pointers
CLO 2
Note: The following rubrics/metrics will be used to grade students’ output in the lab
exercise.
Trait (Excellent) (Good) (Fair) (Poor)
Able to identify Able to identify Able to identify Unable to
correctly all correctly all only one input or identify any
Requirement input and output input and output output input and output
Specification(30pts) and provide (25-17pts) (22-14pts) (20-11pts)
alternative.
(28-20pts)
Able to apply Able to apply Able to identify Unable to
required data required data required data identify required
type or data type or data type or data data type
Data type(20pts) structure and structure and structure but (9-11pts)
produce correct produce partially does apply
results (18- correct results correctly (12-
20pts) (15-17pts) 14pts)
The program The program The program The program
works and meets works and meets produces correct produce s
Input all all results but does incorrect results
Validation(20pts) specifications. specifications. not display (9-11pts)
Does exception Does some correctly Does
al checking for checking for not check for
errors and out- errors and out of
errors and out of
of- range data range data (15- range data (12-
(18-20pts) 17pts) 14pts)
Unable to run Able to run Able to run Able to run
program (10pts) program but program program
Free from syntax, have logic errorcorrectly without correctly without
logic, and runtime (8-9pts) any logic error any logic error
errors (10pts) and display and display
inappropriate appropriate
output (6-7pts) output (5pts)
The program The program The program The program was
was delivered on was delivered was delivered delivered after
time (10pts) after 5 minutes after 10 minutes 15 (or more)
Delivery (10pts)
from the time from the time minutes from the
required. (8-9pts) required. (6-7pts) time required.
(5pts)
Use of Comments Specific purpose Specific purpose Purpose is noted No comments
(10pts) is noted for each is noted for each for each included. (5pts)
function, control function and function. (6-
structure, input control structure. 7pts)
requirements, (8-9pts)
and output
results. (10pts)
Topic Pointers
Lab Activity No 4.1
Lab Activity strcat function using pointers
CLO 2
Requirement Specification
(30pts)
Data type (20pts)
Input Validation (20pts)
Free from syntax, logic,
and runtime errors (10pts)
Delivery (10pts)
Use of Comments (10pts)
TOTAL
Topic Pointers
Lab Activity No 4.2
Lab Activity Reverse string
CLO 2
Requirement Specification
(30pts)
Data type (20pts)
Input Validation (20pts)
Free from syntax, logic,
and runtime errors (10pts)
Delivery (10pts)
Use of Comments (10pts)
TOTAL