Sunday, June 9, 2013

Goals for the rest of 2013

Since late last year I had some plans about what I wanted to accomplish this year in terms of technical knowledge and programming.  The ideas have been floating in my head, and I have already accomplished several, but I think it will be nice to write them here and see how I much I get done by year's end.

  1. Work with C++ again.  -  C++ was actually my first "real" programming language that I learned to the point I could build some non-trivial applications.  During my time in university, I focused on Java and C, and my C++ knowledge accumulated a fair amount of rust.  This year I plan to get back to working with C++ to the point that it becomes the go-to language when solving computational problems.
  2. Learn Qt.  -  One of the reasons for going back to C++ is that I want to do some GUI applications that can run in both Windows and Linux.
  3. Learn OpenGL.  -  I bought a book about DirectX last year and read a few chapters, but decided that OpenGL would be a better choice since I eventually want to program a game for Android, which only uses OpenGL.
  4. Review algorithms  -  It is my personal belief that I should know everything covered in a standard college algorithms course by heart, and can be able to apply the knowledge at any time.
  5. Code at least one game by December 31, 2013.  -  I've been trying to code a game since I was in high school.  It is the reason I studied Computer Engineering in school.  Too many things have gotten in the way in the past.  It is time.

Thursday, May 30, 2013

Redirecting files to standard input in Visual C++ 2012

Back in my university days when I use to code on Linux, I used pipping quite a bit to pass files to my programs.  What is pipping? You can think of it as redirecting the input inside a file to the standard input of your program.

Think of it as an easy way to avoid having to type stuff over and over again.  For example, you might be writing a program and you have a "fixed" input that you want to keep using as you modify and debug your program further.  If you are working from the console, you will have to type this input many times "by hand."  A better approach is to place this fixed input inside a text file and "pipe" it to your program.

One way to do this is to add the input text file in question to the directory where your executable resides and use the < character like the following:

C:\MyProject1\MyProgram.exe < input.txt

This is fine if you intend to debug by using lots of cout calls.  I tend to dislike this approach since I want to use Visual Studio and all its great debugging features.

In order to accomplish the same task and pipe the file to Visual Studio, you can redirect the file by going to  (Visual Studio 2012 Pro):

Project -> Properties -> Debugging -> Command Arguments

Add the following to your Command Arguments

< input.txt

In order for this to work without specifying the full path to your file, make sure to place the file in the same location where VS creates source files.  Now when you debug from within VS you don't have to type the input again and again!

Sunday, August 26, 2012

Udacity CS101

Decided to get back into learning mode after being lazy for half of the year. This time, I'm learning a new programming language just for fun.

Late last year I completed the A.I. class offered by Dr. Sebastian Thrun and Dr. Peter Norvig, so it was natural to check Udacity for their course offerings. Since most of the classes offered at Udacity use Python, and because I haven't been exposed to the language in the past, I decided to start with CS101 to get a feel for the language, before moving to the more advanced courses.

After 4 weeks, I'm in unit 5 having completed all the exercise that accompany each unit, and also the extra practice material that was recently added. So far I'm very impressed with the quality of the class, and it probably does a better job as an introduction to Computer Science than some of the introductory classes I took in college.

In the short 7 weeks that the class is designed to take, the student is introduced to non-trivial problem solving with Python. You get to program a very rudimentary search engine, and most importantly, you are briefly introduced to quite a few C.S. fundamentals.

Overall, I give the course my highest recommendation. It is my belief that it would be especially useful to high school students who are thinking about majoring in Computer Science, but haven't been exposed to the field before.

Saturday, August 25, 2012

Accelerated C++ Solutions - Posting partial solutions

It has been a long time coming since I announced that I was going to post the solutions to the book Accelerated C++. Well, I got really lazy and procrastinated. Then at the beginning of the year, life got a little complicated so I put this on hold.


Anyway here it is. I'm posting solutions starting from chapter 2 to the beginning of chapter 12. You will notice that some problems are missing, especially all the *-0. The problems that are missing are what I remember being trivial, such as typing in the source code from the examples in the book, or slightly modifying a previous problem.


I'm really sorry, but I won't be providing detailed explanations for each solution like the author in parks computing, which you can see in a previous post I made. It would just take too much time. However, you can leave a message here, or shoot me an e-mail to arroyjose at gmail dot com, if you need clarification or help.


NOTE These are a set of solutions to the problems. There are many other ways to get the correct result, that aren't the same as mine, and in all likelihood, there are probably better solutions. A word of advice is to try to figure out the problems yourself, and use my solutions to see how another person implemented the same answer.


NOTE 2 I used Visual Studio and I'm providing the solutions in the folder structure that Visual C++ creates for a project. My apologies to those in Linux and other systems.


NOTE 3 The solutions are provided in a dropbox link until I find a better way to distribute them. At some point I intend to finish all the problems, but I don't want to give a date.


Here they are. Good luck!


Accelerated C++ Solutions

Thursday, July 14, 2011

Accelerated C++ Solutions

Well, I'm going to start posting the solutions to the book, but I'm going to skip all solutions from the first two chapters because I believe most of them are trivial. Chapter 3 is where the questions start to ramp up in difficulty. Also, I'm skipping all the *-0 exercises since those are just about running the code from each chapter. If you still want to check the solutions for the first two chapters check:


http://www.parkscomputing.com/accelerated-cpp-solutions/


The author, Paul, is also working on the solutions to the book, so you can use his as another approach to take in the exercises.

Wednesday, June 29, 2011

Testing

#include <iostream>
#include <string>

using namespace std;

int main()
{
 cout << "Please enter your first name: ";

 string name;
 cin >> name;

 const string greeting = "Hello, " + name + "!";

 cout << "Enter the vertical and horizontal padding: ";
 int padTopBottom;
 int padLeftRight;
 cin >> padTopBottom >> padLeftRight;

 const int rows = padTopBottom * 2 + 3;
 const string::size_type cols = greeting.size() + padLeftRight * 2 + 2;

 cout << endl;

 for (int r = 0; r != rows; ++r)
 {
  string::size_type c = 0;

  while (c != cols)
  {
   if (r == padTopBottom + 1 && c == padLeftRight + 1)
   {
    cout << greeting;
    c += greeting.size();
   }
   else
   {
    if (r == 0 || r == rows - 1 || c == 0 || c == cols - 1)
    {
     cout << "*";
     ++c;
    }
    else
    {

     // The line where the greeting goes.  Should only be here twice
     if ( r == padTopBottom + 1 )
     {
      string space(padLeftRight, ' ');
      cout << space;
      c += padLeftRight;
     }
     else
     {
      string space(cols - 2, ' ');
      cout << space;
      c += cols - 2;
     }
    }
   }
  }

  cout << endl;
 }

 return 0;
}

Accelerated C++

Now that I'm done with school I finally have some time to sit and re-learn C++. The last time I did any substantial programming with the language was during an internship back in 2007. To help me in this task, I've decided to read a book, which I feel is the most conformable way of learning things for me.

Since I already know a large portion of the syntax, and semantics I wanted to pick a book that didn't delve into beginning territory, and instead focused on people who already know how to program but want to learn the C++ language quickly. Most of the time, the type of books that cater to programmers are titled "Pro" for example "Professional C#," etc. The reason I'm avoiding books such as C++ Primer Plus, Beginning C++, C++ in 21 days and others like them is not because they are bad, but because too much time is spent explaining the fundamentals of programming, not to mention that some of these tomes are 1000+ pages long.

There is one very popular and well reviewed book for C++ that has stood the test of time due to its unique approach of teaching the language: Accelerated C++. It covers just as much material as other beginners books and doesn't spend hundreds of pages teaching how to use a for loop. My goal is to read and do all the exercises in the book by August 15 of this year.

In the last two weeks I've read the first 4 chapters and I'm still working my way through the exercises in Section 3. What I'm finding is that searching for the solutions online has shown that only a few people have posted them, but not for the entire book. So I thought it would be a cool idea to post all the solutions here in my blog as I work my way through each chapter. Perhaps it will give me a little more motivation to read the book in its entirety, and some people will find it useful to see how I approached each exercise.