#include <iostream>
#include <iomanip>

using namespace std;

int strlen(char* s) {
    int count = 0;
    while(*s++) ++count;
    return count;
}

char* strcat(char* s1, const char* s2)
{ char* p;
  for (p=s1; *p; p++)
    ;
  for (; *s2; p++, s2++)
    *p = *s2;
  *p = *s2;
  return s1;
}

int* fun(int* b, int* &c) {
    b--;
    *c = (*b)%2;
    c = c + 2;
    *c = *c + 2;
    cout << "\n*b=" << *b
         << "  *c=" << *c << endl;
         return b + (*b);
}
int main()
{
//    //4
//    int a[5] = {3,4,-1,1,3};
//    int* p = a;
//    int* q;
//    while(p != &a[4])
//        q = fun(&a[1], p);
//    cout << "\n*p = " << *p
//         <<  "  q = " << *q << endl;
    //1a
//    int x;
//    cin  >> x;
//    int words[x]; // error, static array cannot be bound at runtime
//    words[0] = 404;
//    cout << words[0];
//    string words1[2];
//    words1[0] = "Gandalf";
//    // fix this with
//    cout << endl << words1[0];
//    //or
//    string* words2 = new string[2];
//    *words2 = "Merlin";
//    cout << endl << *words2;
//    words2++;
//    *words2 = "Sarumon";
//    cout  << endl << *words2;


////1b
//    int y;
//    cin >> y;
//    // if 0< y< 10 // this is soooo wrong
//    if(y>0 && y<10)
//        cout << "y is between 0 and 10";

//1c
//    double investment = 2000.0;
//    double return1 = 1.016 * investment;
//    cout << setprecision(2) << fixed;
//    cout << "The reutrn on your invsetment is $" << return1;
//
//
//
//    char c;
//    cin >> c;
//    //if(c=="f" && c == "F")
//    if(toupper(c)=='F')
//        cout << "You typed an upper or lower-case F.";
//    int a[4]={10,20,30,40}; // Create an array a with values 10,20,30,40
//    int* p;  int* q;  // creaed two pointers integers
//    p = new int; //creates a pointer to the first address of a
//                 // memory bloc and allocates memory for it.
//    cout << "\np = " << p;
//    cout << "\n*p = " << *p;
//    *p = 55;  // Assigns the value 55 to the memory location p points to.
//    q = a; // assigns the address of the first element of a to q
//    cout << "\nq = " << q;
//    cout << "\n*q = " << *q++;
//    cout << "\n*++q = " << *q;
//    *q = *p; // assign the value p points to to the value q points to;
//    cout << "\na[1] = " << a[1];
//    cout << "\n*q = " << *q;
//    delete p; // return the memory allocated for p to the heap

//3a
//    string s = "gandalf";
//    s.insert(3,"SAM"); //ganSAMdalf
//    cout << s << "\n";
//    s.erase(2,4); //gadalf
//    cout <<  s << "\n";
//    s = s.substr(2,4); //dalf
//    cout << s;

//3b
//    int a  = 4, j = 1;
//    do {
//        cout << j << "+";
//        j = j + 2;
//        if(j>a)
//            j--;
//    } while (j < 8);
// 3c
//    cout << setprecision(2);
//    for(int i = 5; i > 0; i--) {
//        cout << i/3.0 << " ";
//    }
// 3d
//    int a[4] = {3,4,-2,6};
//    for(int i = 3; i>0; i--)
//        a[i] += a[i-1];
//    for(int i = 0; i < 4; i++)
//        cout << a[i] << " ";

//fccpp8-21

//fccpp8-24
//    char* teststr = new char[10];
//    teststr = "hello there Mr Peabody, how are you today?";
//    cout << "\nstrlen(" << teststr << ") = " << strlen(teststr);

char* str1 = "cat";
char* str2 = "dog";
cout << strcat(str1, str2);
    return 0;
}
