Nov 29 2015

Mission Accomplished – Final Lab 7

Filed under General

I want to start this post by saying: “Mission Accomplished!”  I have finished my last lab and sent it to my professor for evaluation. By far this lab without a doubt has been the hardest and most complicated lab I have worked with. I had to read not only the professor’s notes but also look for information outside like Google, YouTube and other sites to understand some of the complicated concepts used in this lab. Also, it took some time to understand what I was supposed to do in some problems.  However, it gave me a sense of accomplishment like a rewarding sensation when I saw my programs run successfully.

On this final lab I started to work with pointers. At the moment I saw the function of a pointer I thought that they work similar to a hyperlink, when you hyperlink a word you give it an address and if a person clicks on it you are sent to that address. Also, I learned how a dynamic array can have the same behavior of a vector.  Finally, the multidimensional arrays are very helpful when I wanted to make a table (ex X,Y).

My overall experience in this class was fun. I have learned many concepts of c++ , just to mention a few:

  • Conditional statements
  • Data Types
  • Arrays
  • Pointers
  • Loops
  • Functions and others.


In this class, I had a mix feeling of emotions like anger, sadness, accomplishment and most of all joy. At first I wasn’t sure I wanted to make a career in programming but after taking this class I see clearly that I want to take this path. I can’t wait to take part two.

No responses yet

Nov 16 2015

A real useful tool…. Lab 6

Filed under General

I just wanted to share a quick comment that as Labs become more and more complicated in addition to reading the chapter slides and the class book, I have found very but very useful to use

  • YOUTUBE as a tool

To learn (NOT COPY IDENTICALLY), but to get an idea on how to accomplish what I need to do

  1. Examples of how to do more complex things
  2. Examples about the topics (eg. Hexadecimal addition, Medians, Quartiles,  Standard Deviation, Sorting, etc)
  3. Useful formulas to complete the labs
  4. Libraries that I can add

In this lab I had to do some research on many of the tasks for this assignment.

  1. Find the Median reading 2 files containing integer numbers and later the quartiles (This part was tricky) because quartiles are suppose to find in a list of sorted numbers the position which divides in 4 equal parts the list… But what happens when you have an ODD number list
    • ex. 1234 5 6789 – In this case 5 is the median which is what we find first to determine the 1st and 3rd quartile.  But if you notice you end up with an even number in the list after finding the median on each side of the median, so you would need to do an average to find the 1st and 3rd quartile.
    • ex2.12345 6 78901 – In this case 6 is the median but different from the first example you end up with an ODD number so the formula to use to find the quartiles is different
  2. For the second problem it was calculating the Standard Deviation but this was’t too hard as it was just a matter of reading the files and applying the formula to calculate standard deviation
  3. Merge two number files and create a final sorted file… I don’t know why… I tested several examples and it worked on my pc not sure why it didn’t work on the professor’s computer… My strategy was to :  Read the 1st file and write it in the output, Read the 2nd and write it in the output, Read the merged file and save values in an array, sort the array and finally write sorted list into the file… not sure what went wrong… Below is my sorting logic
    //repeat until the numbers are in order
    while(not sorted)
    sorted = true;
    for(int j = 0; j<recordsInFile-1;j++)
    if (next < current)  // Compare value of the array for position J VS J+1
                    //In these following lines do the switch


    sorted = false;


  4. Exercise 4 was the most challenging and interesting… it was Hexadecimal addition but only 10 digits were used… if the addition exceeded it gave an overload error… I used char arrays to complete this one
  5. And finally delete repeats was basically comparing each element of the partial array vs the entire array list…  For this I used a nested For to move in the array…

More to come… Thank you!

One response so far

Oct 31 2015

Learning about arrays…

Filed under General


On Lab 6 we began to learn about Arrays… And I don’t know if this is a good comparison but to me arrays remind me of Lockers…  Why? because they are a series of spaces divided and numbered… and that can be used to store anything… Using that same comparison in the computer we can think of arrays as spaces of memory that can store different types of information and that has an index which begins at 0.

We can have arrays to store all sorts of data types…

  • char
  • string
  • int
  • long
  • bool

and just like lockers you can insert something or you can remove something or it can be left empty.

  • An array can be declared this way…  int myArray[5] this creates 6 spaces in memory (as arrays begin to count at 0) and it stores integer.
  • To insert data into an array …. myArray[0]=2 this inserts the value 2 in the 1st index of the array (thinking of the locker locker 1).
  • To select data from an array… myVar = myArray[0] this assigns the value of the array in that location to the variablea

Again array can hold different types of information… and are very useful to store information that can be used while the program is running in memory.

They can also be used in functions as arguments of the function passed as proper parameters void myFunction(char a[]) and the program would use the values of the existing array.

To move in an array we can use any loop … For example

                                                                                                           for(int i=0;i<arraySize;i++)

                                                                                                                 myArray[i]  //do something with the value stored in the array

Finally we can have multi dimensional arrays… so using the same example as the locker we can have lockers with multiple rows and columns….

more to come….


No responses yet

Oct 28 2015

Learning about how to read/write to and from files using stream library

Filed under General

OK…So things are getting really interesting at this point because with everything we have learned so far we can do more advanced things in C++.

Now we are learning about how to read from files and also how to write to them.

There are 2 types that we need to use for this

  1. ifstream – this is to read and import data from a file into C++ program
  2. ofstream – this is to write and export data from C++ program into a file

To have access to these types we need to add to the header the library #include <fstream> or file stream library.

And the main functions to remember are

  • open(“filename”) to open and connect to the file having access to it.
  • close() – important to disconnect to avoid corrupting the file
  • if i have a variable ifstream inputfile then I can use the same command as cin to read information from the file into a variable example inputfile >> variable
  • same if i have a variable ofstream outputfile then I can use the same command as cout to write information from C++ into the file outputfile << variable
  • To test if it’s the end of the file we can use the while command like for ex.  while(inputfile >>variable) if True it will read and something can be done with the data from the file
  • There are some other nice features that I learned can be used to test if the file was opened successfully or to format the data

thank you! More to come….

No responses yet

Oct 20 2015

Trying to Earn Extra Credit from COJ (Caribbean Online Judging)

Filed under General

I registered in the COJ contest to see if I can earn some extra credit for the class… There are a lot of people from different countries…

And many from our own College….  This is going to be a great learning experience and also I really hope it will help me improve my grade from my first mid-term.


So far I have submitted 2 programs

  • A+B Problem – For this problem we just need to calculate A + B, numbers given in the input.  NOT AS EASY AS IT SOUNDS!!!!  Because the input line will be separated by a blank space (Ex 1 3) and C++ stops reading if it finds a blank space…  So I had to use a new command getline(cin,S) to read the line into a string variable (in this example S).  And then use string functions (which I knew from Excel).  Like:
  1.   S.substr(startposition,length) //to read a part of the text
  2.   S.find_first_of(” “) // to find the firs position of the blank space
  3.   S.Length //to find the length…
  4.  atoi() // to convert a number from an Alphabet to an Integer (atoi)
  • General Elections – This one was very similar to the first problem I was able to use the same functions to solve this problem. Counting votes to declare winner of election.

more to come… thank you!

No responses yet

Oct 13 2015

Lab 5 Void Functions & by Reference

Filed under General

In Lab 5 we are now learning about Void functions or functions that do not return a value and about calling Functions using parameters by reference instead of by value…

These can be called by simply setting the data type to void.

  • Ex    void myFunction(int Input1)

Functions that are called using parameter by reference work by receiving the address to the memory location where the input variables are stored…

Versus calling a function by value where the function creates new local variables (accessible only from inside the function) or the Scope is inside the function.  Which is very useful because this way we can share, use and update the same variables in different functions (called by reference).

These can be called by simply adding an “&” sign next to the parameter.

  • Ex void MyFunction(int &Input)

These 2 are example of ways to “encapsulate” the code.. or in other words hide the code and leave in the program only the function calls.. This makes a program more readable and neat and easier to understand.  A good way to explain this is when you use the function SQRT you don’t need to know what the function SQRT does inside or what is the code used to create it… You just want that when you call this function it returns the Square root of the number you entered …

Lab 5 most challenging problem was the one for Puzzlevania.. but at the same time very interesting…

In summary this lab was to determine who would win in a duel granting them different accuracy levels to each and generating random numbers to determine if the shot was a hit or a miss.  The only problem I found is that the Random number logic does create different numbers but it ALWAYS … creates the same different numbers .. So the final result will always be the same… I also learned that in reality C++ DOESN’T GENERATE RANDOM NUMBERS… it is a pseudo random number because it uses a formula to generate them…

The other lab problems I found OK to complete….

More to come… thanks!

No responses yet

Oct 11 2015

Feeling a bit dissapointed

Filed under General

First mid-term was a learning experience for me… I am doing very well on the Lab works and Quizzes…

But I just did not have enough time to complete the programming question of the test.

I learned for next time to try to complete this part first then do the rest.

Something new I learned (or at least learned how not to do it), is that I tried to implement the programs to clear the screen and show a blank screen whenever the user entered an incorrect value into the program (to show a clean screen and let them try again), trying to make it less messy…

However the way I tried to do it was thru the use of the SYSTEM command… system(“CLS”), I learned that this is an Operating System command not a C++ native command.  So not that I was doing something entirely wrong but this doesn’t work the same way in all operating systems… At first I believed that by including a library called <cstdlib> I would fix the problem but this was incorrect so I received the same comment about the SYSTEM(“CLS”) error from my lab 3 exercise, since I use Windows to create the programs and Lynux is a different Operating System.

I will try to earn extra credit by taking opportunity of a programming activity COJ mentioned in class… more to come….


No responses yet

Oct 02 2015

Working on Lab 4 – functions & mid term coming…

Filed under General

Well… the mid term exam is next week and I need to balance everything… Meaning study for mid-term … Keep up with the quizzes and Finish this Lab 4

So far in this lab 4 is about functions…. They are pretty interesting.. and very useful…

From what I can see it helps to avoid repeating the same code over and over in the program…

something I learned is that it seems to have these important parts:

1. Data Type output by the function

2. Data Type input into the function

3. The C++ body

4. The return statement…

ex. string myfunction(int input)


C++ //do something

return string



The more tricky exercises in this lab was the one to write the words to the song about bottles of beers!!!

The program receives a number (for example 10) and the program needs to create the “ENGLISH WORDS” to the song…

so it should output “Ten bottles of beer on the wall, ten bottles of beer.  Take one down pass it around, now you have Nine bottles of beer on the wall”..

until it reaches 0… I found it fun to solve… I just used a function that receives an integer number then using the integer division and returned the string to the number… ‘

Here is an example of how I solved it:

  • for example If NUMBER/10 = 9 then “NINETY” else if NUMBER/10=8 then “EIGHTY”….

And for the other part I used the MODULUS or remainder function

  • for example If NUMBER%10=9 then “NINE” else if NUMBER%10=8 then “EIGHT”… And so on and so forth…


The other interesting one was about the “TIME MACHINE” program… and it takes 2 different hours to calculate the difference in total number of minutes between the 2…

It receives 6 inputs… Starthour, StartMinute, Start AM/PM , EndHour, EndMinute, End AM/PM…

The trick here was to convert the total hour into minutes…. and there are 3 special times you want to consider… 12am = hour 0, 12pm = hour 12 and any other PM = hour+12…

The rest is a simple difference on the end time vs start time….


The others were just using formulas… Well I hope to submit my lab this weekend….

One response so far

Sep 19 2015

Lab 3 Requirio un poco mas de esfuerzo…. It required a little more effort this time…

Filed under General

This LAB3 on COMP3010 wasn’t particularly difficult as it was long….

It did require a little more effort but it wasn’t impossible either… Last one I got a 96% because I used a SYSTEM command which didn’t compile in the professor’s computer plus I don’t think I understood very well the instructions on one of the LAB Exercises… But I was happy because I received 2 points for extra credit…

This Lab consisted of:

1. A program to convert decimals to Roman numbers

2. A program to read you Birth Date and tell you your Horoscope

3. A program to calculate Declining Loan balances..

4. A program to Calculate the Call Rate based on the day of the week and the time

5. A program to calculate the Person’s dress size (Hat, Jacket, Waist) based on their weight/height/age…

6. Same as program 5 but in 10 years…

To those future students that need to take COMP3010… Is just a matter of practice and is possible…. OK… until next post…

No responses yet

Sep 08 2015

Yo al completar el Lab 2…

Filed under General

Ja Ja Ja.. se que se pondra mas dificil....

No responses yet

Older Posts »