Monday, 24 September 2012

cout << "First tutorial." << endl;

As the semester starts to pick up its momentum, our group has the chance to experience the joy of learning C++, or basically learn how to transfer our previous knowledge to different programming languages.

Because of the fact that our group members have had different experience with C++ (or haven’t had any), there were multiple opinions regarding the questions raised on our Friday tutorial.
No matter what, the first week’s project helped us to refresh our Java skills, as they had rusted during the summer. Of course ‘googling’ and checking last year’s assignments helped us to solve the few problems that we encountered with. 

During the development of our software the team didn’t had any major arguments or difficulties working together, thought next time the organization could be done better by having a better documentation of what we want to achieve and how it should be done.

The first lecture gave us a good overview of what to expect from this course, how our work will be marked and it reminded us about plagiarism and code re-use.

Comparing Java and C++ versions of ‘Hello world’ the first thing that was noticed is that for every Java project you have to declare a new class and set the access level modifier for the main method, none of that should be done for the C++ version. That is because Java is OOP an opposite approach for C++ is that you can decide whether to code object oriented or not. There are few other things that were different in those two examples, like the fact that C++ returns 0 if the method has executed correctly. Also in Java there was no need to include extra libraries to print out something in the console, comparing to C++ where it is needed to include iostream library. C++ has a different way to output streams to console using “cout” and “<<”, plus now to unite strings and variables when outputting them you have to use “<<” or “>>” instead of “+” as we were used to do in Java. All in all, it is still programming and the principles are kept the same in almost every programming language, the most noticeable thing that a changed is syntax.
The C++ compiler gives you enough information to find errors and warnings.
As for the variables, there were not many differences that we noticed, the ones that we did were
* Need to include “string” library to use strings.
* Define a strings using “string” not like in Java “String”.
* New ways of defining strings – typdef, enum.

The syntax for defining constants in Java and C++ differs. In the first case we would use “final static” in front of our variable, but in C++ you use just “const”, this constant cannot be changed (that is why it Is a constant).

As I mentioned before, the output is a bit different in C++ than it was in Java, you have to do a std::cout << “somethinghere” << endl; instead of System.out.println(“somethinghere”);, it’s more difficult to tell about the input differences, because last year we were using Genio library which helped us to get the input from users, now we just use cin >> string; ( it is important to remember the difference between >> and << ).
Also loops are the same as they were in Java.

More or less there was nothing surprising during the last weeks lecture because of the previous programming knowledge, though I am sure that it will get more interesting during the next weeks.

1 comment:

  1. A very good style, the chattiness means it reads like a blog post! You have summed up the main points from the week well. I am really glad to hear that the week 1 JAVA project was useful. You are correct, there is less code needed to write hello world in C++ (due to lack of OO) as oppose to JAVA. However, this can cause obfuscation as well as simplicity! Overall, an excellent blog you answered all the important questions really well.

    ReplyDelete