Thursday, December 2, 2010

Practice Solution for C1

Write a program that print Good morning, Good afternoon, Good night in 3 separate lines. Tips, to go to next line, use endl. The output of the program should look like this.
Good morning
Good afternoon
Good night
The solution of the practice problem is below. If you type the keywords correctly, you should get the program to compile and finish in about 10 to 15 mins. The idea is to test if you know what does endl do. Test it out, try to see what happen if you don't add endl like we did in the solution. You will get everything on the same line.
Good morningGood afternoonGoodnight
So what you want to do is to add a space at the end of the each word, like below.
cout << "Good morning " << "Good afternoon " << " Good night " << endl; 
// output will be like this: Good morning Good afternoon Good night
Finally, here is the solution to the question above. If you have any question, please feel free to email me or post question in the comment section below. Happy coding! :)
/*
 *  csci135p1.cpp
 *  Solution to the practice, just make sure to type endl for the next line
 *
 */

#include <iostream>
using namespace std;

int main()
{
   cout << "Good morning" << endl;
   cout << "Good afternoon" << endl;
   cout << "Good night" << endl;
   return 0;
}

Wednesday, December 1, 2010

csci135c1.cpp

Since this is the first tutorial, and I am still trying to figure out my way of how to do this. Let's do a easy example, the well know "Hello World" example. This program will display a message to the terminal.
/*
 *  csci135c1.cpp
 *  The classical program that display a message to the screen.
 *  The basic structure of the c++ program, and the main function.
 *
 */

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello World! " << endl;
    cout << "I like programming, programming is fun. " << endl;
    return 0;
}
The first section of the code is the comment, there are a few ways to include comments in our source code. The first way is only for a single line, it seems to be the easiest way. It is useful for variable descriptions or function's comment. The second one is good for comments that is a few lines. But for the second way to display comment, please remember to end the comment with */. Or else it will give you a compiler error. Of course, you can go fancy with that method. But some of the professors might not like it. They might prefer the first way, just add // to every single line.
// This is a comment

/* This comment can
   be written over
   a few lines, just remember
   to close it! */

/* 
 * Look at this
 * beautiful
 * comment style.
 *
 */

// One line of comment
// Another line of comment
// You can type as many single lined comment as you want
The first thing you see after the comment section will be the include statement, we will discuss it more in the later tutorial. For now just remember to type it when you want to do any kind of displaying messages, the include is to let the linker know I am including part of the codes from different header files. 
#include <iostream>
using namespace std;
The main function's name... is called main. And int represents integer, therefore main function will return an integer. The integer is used to determine the state of the function, whether it is not working, it crash, or anything important the program is going to telling the operating system or user. Usually 0 means it is normal, and the rest other is considered to be not "normal". But what it returns is purely based on the what the programmer wants it to be. The meat of this program is the following line.
cout << "Hello World! " << endl;
cout means the stream that the data is sending to, << is called the insertion operator, it will send the data into the stream. And endl; is a symbol to let the program knows it is going to go to the next line. It is possible to link the input data like the following to create something like this. Notice the last example, show you how to control how many line to skip.
cout << "Regular style, outputting message. " << endl;
cout << "There " << "are " << "more " << "messages. " << endl;
cout << "Let's skip 5 lines? " << endl << endl << endl << endl << endl;
Thoughts: This first tutorial is a lot longer than what I thought it will be... I did not expect it to be so lengthy. most programmers can write this piece of code within 20 seconds, when trying to explain it without any prior knowledge is a different story. And I will have to double check the facts of my explanation.

Practice Problem 1:
Write a program that print Good morning, Good afternoon, Good night in 3 separate lines. Tips, to go to next line, use endl. The output of the program should look like this.
Good morning
Good afternoon
Good night
See here for solution

csci135c1.cpp

Since this is the first tutorial, and I am still trying to figure out my way of how to do this. Let's do a easy example, the well know "Hello World" example. This program will display a message to the terminal.
/*
 *  csci135c1.cpp
 *  The classical program that display a message to the screen.
 *  The basic structure of the c++ program, and the main function.
 *
 */

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello World! " << endl;
    cout << "I like programming, programming is fun. " << endl;
    return 0;
}
The first section of the code is the comment, there are a few ways to include comments in our source code. The first way is only for a single line, it seems to be the easiest way. It is useful for variable descriptions or function's comment. The second one is good for comments that is a few lines. But for the second way to display comment, please remember to end the comment with */. Or else it will give you a compiler error. Of course, you can go fancy with that method. But some of the professors might not like it. They might prefer the first way, just add // to every single line.
// This is a comment

/* This comment can
   be written over
   a few lines, just remember
   to close it! */

/* 
 * Look at this
 * beautiful
 * comment style.
 *
 */

// One line of comment
// Another line of comment
// You can type as many single lined comment as you want
The first thing you see after the comment section will be the include statement, we will discuss it more in the later tutorial. For now just remember to type it when you want to do any kind of displaying messages, the include is to let the linker know I am including part of the codes from different header files. 
#include <iostream>
using namespace std;
The main function's name... is called main. And int represents integer, therefore main function will return an integer. The integer is used to determine the state of the function, whether it is not working, it crash, or anything important the program is going to telling the operating system or user. Usually 0 means it is normal, and the rest other is considered to be not "normal". But what it returns is purely based on the what the programmer wants it to be. The meat of this program is the following line.
cout << "Hello World! " << endl;
cout means the stream that the data is sending to, << is called the insertion operator, it will send the data into the stream. And endl; is a symbol to let the program knows it is going to go to the next line. It is possible to link the input data like the following to create something like this. Notice the last example, show you how to control how many line to skip.
cout << "Regular style, outputting message. " << endl;
cout << "There " << "are " << "more " << "messages. " << endl;
cout << "Let's skip 5 lines? " << endl << endl << endl << endl << endl;
Thoughts: This first tutorial is a lot longer than what I thought it will be... I did not expect it to be so lengthy. most programmers can write this piece of code within 20 seconds, when trying to explain it without any prior knowledge is a different story. And I will have to double check the facts of my explanation.

Practice Problem 1:
Write a program that print Good morning, Good afternoon, Good night in 3 separate lines. Tips, to go to next line, use endl. The output of the program should look like this.
Good morning
Good afternoon
Good night
See here for solution

Monday, November 29, 2010

Textbook Resource

  • Small C++ How to Program (5th Edition) - the classroom textbook used in the csci135, I think most of the the 135s in hunter college used this book as well. I like this book, besides the interesting cover (with a microscope observing an ant buddy). It provide easy to understand explaining, and the colored coding highlight also help more easy understand of what the code is doing. However, I recommend not to get too attached to their use of spaces in between the loops.
    // This book like to add space everywhere
    if ( int i = 5 ) 
    // Compare to regular style
    if (int i = 5)
    
    I think it does not hurt to pick up a used copy, it is very user friendly, while it does not go into absolute details and provide all the c reference like other books do, I think it is very straight forward.
    • Brand New: $71.40
    • Used (condition like new): $19.08

  • C++ Primer Plus (5th Edition) - a well known favorite introduction textbook that many C++ programmer read at least a few times. It goes into great detail of explaining everything in length. It fills all the holes left out in the small C++ textbook, granted, this book is about 2-3 times as big as this book. I think this book is a must read for all student who completed csci135, preferably in the winter or summer break, about 40% of the things will be a review. But there are a lot of other details and area is new, highly highly recommended. And the cost of this book is cheap, pick up one please. This book also gives you a great deal of exposure to all the topics in csci135 that the classroom does not cover fully. (It is not the class's fault, we only met twice a week for 1 hour and 15 mins, the professors only have time to cover the basics). Great read, great read.
    • Brand New: $37.79
    • Used (condition like new): $29.99

  • Saad's notes -  this is sometimes referred as notes, but it is almost a fully length ready to go textbook in my opinion. It is written by professor saad from hunter college. If you ever happened to find out he is teaching it. Please consider take it, it will be difficult, but it will be well worth your time. It is not an easy A by any mean, but, you will learn a lot. This book is written in very condensed fashion, by condense I mean he skips the un-needed material and left with only the interesting and useful examples. Moreover, this book has a lot of c reference. It does a great job of exposing student to read c code. A lot of student who called themselves programmer, yes, they are very good at c++ programming, but they can not read c code. Which is a real problem when we are looking for a job, you need to understand them.
    // C string examples from p.100 of the book.pdf
    int main() {
       char s[6]={'h','e','l','l','o','\0'};
       s[0]='b'; //ok at compile time and run-time
    }
    • Brand New: Free
    • Used (condition like new): Print it out maybe costing you a few dollars

Friday, November 5, 2010

First blog post

Hi, my name is George Chan. I am a junior at CUNY Hunter College at New York, studying computer science. My interests is primarily programming, and studying different kind of algorithms. I also very much interested in going to graduate program, and possibly teaching as well. Although I am starting a programming tutorial blog, but I am very much still a student myself. I want to share the experience I got while learning programming.

This blog is served as the main website before I have time to actually have time and the skill create a website. I think it is more important to have a good amount of contents, rather than a flashy website. The goal of this blog is to share my experience as a student learning c++, and give some of my insight to my friends here. There will be a few different kind of materials in this blog, primary will disusing the developing process of my projects, and what is in my mind when I am designing the application.

I hope at the end of it, I can gather up everything here in the blog and create a detailed Qt tutorial based, walk through tutorial. It will be targeted the student who finished csci 235, and teach them how to create GUI using the Qt graphical engine. In our school, we do not have class specially designed to teach students making GUI application. The most we have closest to that is csci493 Window Programming. However, besides that one, I don't think there are much else for us to learn about GUI. And please notice, I am actually still in the process of learning about it too! So you can also see how I am learning it too :)

Lastly, just to be sure, this blog and the youtube channel used to host the video has no relationship with hunter college or cuny or anything else. All the content here only represent my own opinions and thoughts, it does not represent hunter college. And hunter college computer department has nothing to do with this blog as well. If anything on this blog or youtube channel affected the policy of the school or with anyone, please free feel to contact me at this email.

My email address: ywchan(at)hunter(dot)cuny(dot)edu