En - Subject.04 CPP Mod00 7
En - Subject.04 CPP Mod00 7
Summary: This document contains the subject for Module 00 of the C++ modules.
Version: 7
Chapter I
General rules
For the C++ modules you will use and learn C++98 only. The goal is for you to learn
the basic of an object oriented programming language. We know modern C++ is way
different in a lot of aspects so if you want to become a proficient C++, developer you
will need modern standard C++ later on. This will be the starting point of your C++
journey it’s up to you to go further after the 42 Common Core!
• Any function implemented in a header (except in the case of templates), and any
unprotected header means 0 to the exercise.
• Every output goes to the standard output and will be ended by a newline, unless
specified otherwise.
• The imposed filenames must be followed to the letter, as well as class names, func-
tion names, and method names.
◦ The following functions are FORBIDDEN, and their use will be punished by
a 0, no questions asked: *alloc, *printf and free.
◦ You are allowed to use everything in the standard library. HOWEVER, it
would be smart to try and use the C++-ish versions of the functions you are
used to in C, instead of just keeping to what you know, this is a new language
after all. And NO, you are not allowed to use the STL until you are supposed
to (that is, until module 08). That means no vectors/lists/maps/etc... or
anything that requires an include <algorithm> until then.
• Actually, the use of any explicitly forbidden function or mechanic will be punished
by a 0, no questions asked.
• Also note that unless otherwise stated, the C++ keywords "using namespace" and
"friend" are forbidden. Their use will be punished by a -42, no questions asked.
1
Namespace, class, member functions, stdio stream, initialization lists, static, const, and
C++ - Module 00 lots of basic stuff
• You must read the examples thoroughly. They can contain requirements that are
not obvious in the exercise’s description.
• Since you are allowed to use the C++ tools you learned about since the beginning,
you are not allowed to use any external library. And before you ask, that also means
no C++11 and derivatives, nor Boost or anything else.
• You may be required to turn in an important number of classes. This can seem
tedious unless you’re able to script your favorite text editor.
• Your code has to be compiled with the following flags : -Wall -Wextra -Werror.
• In case you’re wondering, no coding style is enforced during in C++. You can use
any style you like, no restrictions. But remember that a code your peer-evaluator
can’t read is a code they can’t grade.
• Important stuff now: You will NOT be graded by a program, unless explicitly stated
in the subject. Therefore, you are afforded a certain amount of freedom in how you
choose to do the exercises. However, be mindful of the constraints of each exercise,
and DO NOT be lazy, you would miss a LOT of what they have to offer
• It’s not a problem to have some extraneous files in what you turn in, you may
choose to separate your code in more files than what’s asked of you. Feel free, as
long as the result is not graded by a program.
• Even if the subject of an exercise is short, it’s worth spending some time on it to
be sure you understand what’s expected of you, and that you did it in the best
possible way.
2
Contents
I General rules 1
3
Chapter II
Exercise : 00
Just to be sure that everybody is awake, write a program that has the following
behavior:
(Use C++ style to interact with stdin!)
$>./megaphone "shhhhh... I think the students are asleep..."
SHHHHH... I THINK THE STUDENTS ARE ASLEEP...
$>./megaphone Damnit " ! " "Sorry students, I thought this thing was off."
DAMNIT ! SORRY STUDENTS, I THOUGHT THIS THING WAS OFF.
$>./megaphone
* LOUD AND UNBEARABLE FEEDBACK NOISE *
$>
4
Chapter III
Exercise : 01
Welcome to the 80s and its unbelievable technology! Write a program that behaves
like a crappy awesome phonebook software. Please take some time to give your exe-
cutable a relevant name. When the program starts, the user is prompted for input: you
should accept the ADD command, the SEARCH command or the EXIT command. Any other
input is discarded.
The program starts empty (no contacts), doesn’t use any dynamic allocation, and
can’t store more than 8 contacts. If a ninth contact is added, replace the oldest contact.
5
Namespace, class, member functions, stdio stream, initialization lists, static, const, and
C++ - Module 00 lots of basic stuff
◦ The program will prompt the user to input a new contact’s information, one
field at a time, until every field is accounted for.
◦ A contact is defined by the following fields: first name, last name, nickname,
phone number,darkest secret.
When a command has been correctly executed, the program waits for another ADD or
SEARCH command until an EXIT command.
6
Chapter IV
Exercise : 02
It’s your first day of work at GlobalBanksters United. You successfully passed the
hiring tests for the programmers’ team thanks to a few tricks with Microsoft Office
a friend showed you. But you know that it was your swift installation of Adobe Reader
that blew your recruiter’s mind. This gave you the little edge needed to beat your oppo-
nents for this job.
Anyway, you made it and your boss gave you your first task. You need to recode one
missing source file because something went wrong. Account.cpp is missing and they use
USB file sharing and not git.
At this point, it will be legitimate to quit this place however for the sake of this
exercise, you will stay.
The Account.hpp file is present and a quick compilation of tests.cpp confirms that
an Account.cpp file is missing. There’s also an old output log that seems to contain the
matching output.
So you need to create a Account.cpp file and quickly write some lines of pure awesome
C++ and after a couple of failed compilations, your program will compiles and passes the
tests with a perfect output, except for the timestamps differences. Damn you’re good!