Thursday, 30 May 2013

Week 12 day 3

It is not uncommon to build up a complex class by declaring simpler classes and including them in the declaration of the more complex class. Fir example, you might declare a wheel class, a motor class, and a transmission class and ect... then combine them into a car class. This declares the relationship between the motor, wheels and transmission.

Tuesday, 28 May 2013

Week 6 day 2

This week I am learning the basics of more function calling and global variables. Global Variables can be called from any function but are dangerous in their own way. they mean that the programmer can call them from anywhere inside the program. They can also be changed in any place from the program to an unintended value which interferes with the proper operation of the intended program.

Week 12 day 2

*/ this is the Cat header file/*
#include <iostream>
class Cat
{
    public:
cat(int initial age);
~cat();
int GetAge() const {return itsAge;} //inline function
void SetAge (int age) {itsAge=age;} //inline function
void meow() const {stc::cout<<"Meow.\n";} //inline function
    private:
int itsAge;
};


*/ this is the cat.cpp file /*
#include "cat.hpp"
#define cout std::cout
Cat::Cat(int initialAge)//constructor
{
      itsAge= initialAge;
}
Cat::~Cat() //destructor
{
}
int main()
{
    cat frisky(5);
frisky.meow();
cout<<"frisky is a cat who is "<<GetAge()<<" years old!\n";
frisky.meow();
frisky.SetAge(7);
cout<<"frisky is now "<<GetAge()<<" years old!\n";
frisky.meow();
return 0;
}

Week 12 day 1

You can also put the definition of a function into the declaration of the class, which automatically makes that function inline for example;
class Cat
{
    public:
      int weight(){return itsweight;}
      void setweight(intaweight);
};

Week 11 day 3

Just as you ask your compiler to make a regular function 'inline' you can make class methods inline. The keyword 'inline' appears before the return type. The inline implementation of the GetWeight() function looks like this;
inline int Cat::GetWeight()
{
        return itsWeight;
}

Week 11 day 2

If you make GetAge() a 'constant' function -as you should- the contract also promises that GetAge() wont change the Cat on which it is called. Each function that you declare for your class must have a definition. The definition is also called the function implementation. Like other functions, the definition of a class method has a function header and a function body. The definition must be a file that the compiler can find. Must C++ compilers want that file to end in ".C" or ".CPP".

Tuesday, 21 May 2013

week 11 day 1

In the class cat declaration, for example you create a contract that every cats age can be initialized in its constructor assigned to it by its SetAge() accessor function and read by its GetAge() accessor. You also promise that every cat will know how to Meow(). Note that you say nothing in the public interface about the member variable ItsAge, that is an implementation detail that is not part of your contract.

Friday, 10 May 2013

Week 10 day 2

This day was a mixture of Trial and error getting a C++ program to call a webpage from your default browser. It took several tries just to get the program to do this simple task. Everywhere I looked the programmers kept putting up this very long code. Yet all it took was:

#include <windows.h>
int main()
{
ShellExecute(NULL, "open", "http://google.net",
NULL, NULL, SW_SHOWNORMAL);
}

That simple program calls the webpage Google.ca.

Tuesday, 7 May 2013

Week eight day 3

This was an interesting learning curve for C++,
#include <iostream>
class Cat
{
    public:
        int GetAge();
        void SetAge(int age);
        void Meow();
    private:
        int itsAge();
};

int Cat::GetAge()
{
    return itsAge();
}

void Cat::SetAge(its age)
{  itsAge = age); }

void Cat::Meow();
{ cout << "Meow!"; }

int main()
{
    Cat Frisky;
    Frisky.SetAge(5);
    Frisky.Meow();
    std::cout << "Frisky is a cat who is ";
    std::cout << Frisky.GetAge() << " years old\n";
    Frisky.Meow();
    return 0;
}

Week 10 day 1

Today I wrote a program what was just above simple for me but for most people it would be still very basic. The idea behind the program was to match a string password so that it would "unlock" the program. Once inside you answered basic questions which didnt do anything but try to make the person understand how the program worked. After that you got to the final question of did you like the program and if you liked it. You got the option to leave a "comment" for the programmer which then created a file called "comments.txt".
This file would hold whatever you said.

I ran into several problems when trying to compile this, the main one was it would only save to a network directory from my computer and no other one. When I tried to get someone else to try the program it would fully run and it would get to the end. BUT it would not save the "comments.txt" file on the network at all. I tried everything until I finally got the program to save it to the local folder on the computer on the network instead of saving it to the network its self.

Sunday, 5 May 2013

week 9 day 1

I missed a week due to not being able to work as I dislocated my lower leg and knee cap and was in to much pain to do anything. I have however started to work with an online Harvard free courseware program.
This program teaches you the basics of computer programming off the CS-50 course.