Hello
World,
For my final blog post I am going to be
making a modest program utilizing templates in C++. Templates, as explained in
my last post, are basically objects. These templates are one of the main
features that differentiates C++ from its counterparts like C and objective C.
As explained earlier, the main feature that differentiates C++ from C is the
fact that C++ is an object oriented programming language.
Templates are really important when
needing to do code quicker and rather more efficiently. You can do things with
templates like make arrays or swap numbers. Rather than making a new array or
swapping in the main code, you could just call the template.
Today, I shall be dividing this post into
two sections. I shall make this post focus on what I am going to do. The next
post I shall implement the code and describe what each part is doing.
The program I shall create is a carnival
program. It is little Timmy’s birthday party and he gets to invite 5 of his
closest friends. He chose to invite Joe, Matt, Mark, Kristen, and Jenna. These
friends shall be stored as strings and called when needed. Timmy and all his
friends decided that the only way they can get all the prizes they want at the
carnival is to put all their tickets together. Each kid has a certain number of
tickets, but technically when they put all their tickets together, they shall
each have a large amount. Every time a child wishes to exchange the tickets for
a prize the number of total tickets shall decrease. The template shall take
place by showing a clear swap of the tickets for the prize. The clerk shall
receive tickets in exchange for a prize. The swap shall be a swap of the prize
which will be an item and the prizeWon which shall be an empty string. Once the
swap occurs I shall show that the child now has the prize, lost the tickets and
then swap those two things back to make it possible to win them a second time
though.
The program shall show all of the prizes
in a list and shall display the prizes won at the end. It shall also display
how many tickets the clerk now has. If the program is not finished, meaning
that the children still have remaining tickets, it shall call itself
recursively to start the program over again until the kids are out of tickets
or do not have enough tickets to purchase what they wish.
More information about how each aspect of
the program shall be in a follow-up post shortly.
Thanks!
No comments:
Post a Comment