#include <iostream>
using std::cout;

typedef char * arrayString;

// ta funkcja nie jest testowana ani uywana w tym listingu
char characterAt(arrayString s, int position) {
   return s[position];
}

void append(arrayString& s, char c) {
   int oldLength = 0;
   while (s[oldLength] != 0) {
      oldLength++;
   }
   arrayString newS = new char[oldLength + 2];
   for (int i = 0; i < oldLength; i++) {
      newS[i] = s[i];
   }
   newS[oldLength] = c;
   newS[oldLength + 1] = 0;
   delete[] s;
   s = newS;
}

void appendTester() {
   arrayString a = new char[5];
   a[0] = 't'; a[1] = 'e'; a[2] = 's'; a[3] = 't'; a[4] =  0;
   append(a, '!');

   arrayString b = new char[1];
   b[0] = 0;
   append(b, '!');

   cout << '\n'; 
}

int main() {
   appendTester();

   return 0;
}

---

#include <iostream>
using std::cout;

typedef char * arrayString;

int length(arrayString s) {
   int count = 0;
   while (s[count] != 0) {
      count++;
   }
   return count;
}

void append(arrayString& s, char c) {
   int oldLength = length(s);
   arrayString newS = new char[oldLength + 2];
   for (int i = 0; i < oldLength; i++) {
      newS[i] = s[i];
   }
   newS[oldLength] = c;
   newS[oldLength + 1] = 0;
   delete[] s;
   s = newS;
}

void appendTester() {
   arrayString a = new char[5];
   a[0] = 't'; a[1] = 'e'; a[2] = 's'; a[3] = 't'; a[4] =  0;
   append(a, '!');

   arrayString b = new char[1];
   b[0] = 0;
   append(b, '!');

   cout << b << '\n'; 
}

int main() {
   appendTester();

   return 0;
}

---

#include <iostream>
using std::cout;

typedef char * arrayString;

int length(arrayString s) {
   int count = 0;
   while (s[count] != 0) {
      count++;
   }
   return count;
}

void concatenate(arrayString& s1, arrayString s2) {
   int s1_OldLength = length(s1);
   int s2_Length = length(s2);
   int s1_NewLength = s1_OldLength + s2_Length;
   arrayString newS = new char[s1_NewLength + 1];
   for(int i = 0; i < s1_OldLength; i++) {
      newS[i] = s1[i];
   }
   for(int i = 0; i < s2_Length; i++) {
       newS[s1_OldLength + i] = s2[i];
   }
   newS[s1_NewLength] = 0;
   delete[] s1;
   s1 = newS;
}

void concatenateTester() {
   arrayString a = new char[5];
   a[0] = 't'; a[1] = 'e'; a[2] = 's'; a[3] = 't'; a[4] =  0;
   arrayString b = new char[4];
   b[0] = 'o'; b[1] = 'w'; b[2] = 'y'; b[3] = 0;
   concatenate(a, b);
   
   cout << a << '\n';
}

int main() {
   concatenateTester();

   return 0;
}

---

#include <stddef.h> // doczono w celu obsugi symbolu NULL; nie jest konieczne, jeli uywamy iostream itd.

struct listNode {
   int studentNum;
   int grade;
   listNode * next;
};

typedef listNode * studentCollection;

int main() {
   studentCollection sc;
   listNode * node1 = new listNode;
   node1->studentNum = 1001; node1->grade = 78;
   listNode * node2 = new listNode;
   node2->studentNum = 1012; node2->grade = 93;
   listNode * node3 = new listNode;
   node3->studentNum = 1076; node3->grade = 85;	
   sc = node1;
   node1->next = node2;
   node2->next = node3;
   node3->next = NULL;
   node1 = node2 = node3 = NULL;

   return 0;
}

---

typedef listNode * studentCollection;

int averageRecord(studentCollection sc) {
   if (sc == NULL) return 0;
   int count = 0;
   int sum = 0;
   listNode * loopPtr = sc;
   while (loopPtr != NULL) {
      sum += loopPtr->grade;
      count++;
      loopPtr = loopPtr->next;
   }
   int average = (sum + 0.5) / count;
   return average;
}

int main() {
   studentCollection sc;
   listNode * node1 = new listNode;
   node1->studentNum = 1001; node1->grade = 78;
   listNode * node2 = new listNode;
   node2->studentNum = 1012; node2->grade = 93;
   listNode * node3 = new listNode;
   node3->studentNum = 1076; node3->grade = 85;	
   sc = node1;
   node1->next = node2;
   node2->next = node3;
   node3->next = NULL;
   node1 = node2 = node3 = NULL;

   cout << averageRecord(sc) << "\n";

   return 0;
}