COS1512_Nov2016_MEMO Tutorials Campus www.tutorialscampus.co.za
Question 1
1.1 strcpy(saveWord, word); // C-strings use the function strcpy to copy one string to another
1.2 if(strcmp(word, saveWord)) // C-strings use the function strcmp to compare two strings
1.3 int j = 4;
Question 2
2.1
2.2
void count(int counter)
2.3
count(--counter);
2.4
assert(counter>=0);
Question 3
3.1
a = (*p1 *2) /5;
3.2
Creating a new int nameless variable an assigning the pointer p1 to point to it
3.3
We cannot assign the address of pointer p1 to another pointer p2, because it has been deleted
pg. 1 for more information contact Nicholas on 083 33 13 124
, COS1512_Nov2016_MEMO Tutorials Campus www.tutorialscampus.co.za
3.4
p3 = &a;
3.5
To access actual value that pointer p3 is pointing to.
Question 4
4.1
#ifndef BURSARY_H
#define BURSARY_H
#include <iostream>
using namespace std;
class Bursary
{
public:
Bursary();
Bursary(int studentNumberP, int yearsOfStudentP, int modulesPassedP);
~Bursary();
int get_Number();
void yearOfStudy(int yearsOfStudent);
friend bool operator==(const Bursary & bursary1, const Bursary & bursary2);
friend istream& operator>>(istream& ins, Bursary& b);
private:
int studentNumber;
int yearsOfStudent;
int modulesPassed;
};
pg. 2 for more information contact Nicholas on 083 33 13 124
Question 1
1.1 strcpy(saveWord, word); // C-strings use the function strcpy to copy one string to another
1.2 if(strcmp(word, saveWord)) // C-strings use the function strcmp to compare two strings
1.3 int j = 4;
Question 2
2.1
2.2
void count(int counter)
2.3
count(--counter);
2.4
assert(counter>=0);
Question 3
3.1
a = (*p1 *2) /5;
3.2
Creating a new int nameless variable an assigning the pointer p1 to point to it
3.3
We cannot assign the address of pointer p1 to another pointer p2, because it has been deleted
pg. 1 for more information contact Nicholas on 083 33 13 124
, COS1512_Nov2016_MEMO Tutorials Campus www.tutorialscampus.co.za
3.4
p3 = &a;
3.5
To access actual value that pointer p3 is pointing to.
Question 4
4.1
#ifndef BURSARY_H
#define BURSARY_H
#include <iostream>
using namespace std;
class Bursary
{
public:
Bursary();
Bursary(int studentNumberP, int yearsOfStudentP, int modulesPassedP);
~Bursary();
int get_Number();
void yearOfStudy(int yearsOfStudent);
friend bool operator==(const Bursary & bursary1, const Bursary & bursary2);
friend istream& operator>>(istream& ins, Bursary& b);
private:
int studentNumber;
int yearsOfStudent;
int modulesPassed;
};
pg. 2 for more information contact Nicholas on 083 33 13 124