one implementation of the exam
This commit is contained in:
2
cpp_module_00/Warlock.cpp
Normal file
2
cpp_module_00/Warlock.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#include "Warlock.hpp"
|
||||
|
||||
35
cpp_module_00/Warlock.hpp
Normal file
35
cpp_module_00/Warlock.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef WARLOCK_HPP
|
||||
# define WARLOCK_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
|
||||
class Warlock {
|
||||
private:
|
||||
Warlock();
|
||||
Warlock(Warlock const & other);
|
||||
Warlock & operator=(Warlock const & other);
|
||||
|
||||
std::string name;
|
||||
std::string title;
|
||||
|
||||
public:
|
||||
Warlock(std::string const & name, std::string const & title) {
|
||||
this->name = name;
|
||||
this->title = title;
|
||||
std::cout << this->name << ": This looks like another boring day.\n";
|
||||
};
|
||||
~Warlock() {
|
||||
std::cout << this->name << ": My job here is done!\n";
|
||||
};
|
||||
|
||||
std::string const & getName() const {return (this->name);};
|
||||
std::string const & getTitle() const {return (this->title);};
|
||||
void setTitle(std::string const & title) {this->title = title;};
|
||||
|
||||
void introduce() const {
|
||||
std::cout << this->name << ": I am " << this->name << ", " << this->title << "!\n";
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
BIN
cpp_module_00/a.out
Executable file
BIN
cpp_module_00/a.out
Executable file
Binary file not shown.
17
cpp_module_00/main.cpp
Normal file
17
cpp_module_00/main.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
# include "Warlock.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
Warlock const richard("Richard", "Mistress of Magma");
|
||||
richard.introduce();
|
||||
std::cout << richard.getName() << " - " << richard.getTitle() << std::endl;
|
||||
|
||||
Warlock* jack = new Warlock("Jack", "the Long");
|
||||
jack->introduce();
|
||||
jack->setTitle("the Mighty");
|
||||
jack->introduce();
|
||||
|
||||
delete jack;
|
||||
|
||||
return (0);
|
||||
}
|
||||
81
cpp_module_00/subject.en.txt
Normal file
81
cpp_module_00/subject.en.txt
Normal file
@@ -0,0 +1,81 @@
|
||||
Assignment name : cpp_module_00
|
||||
Expected files : Warlock.cpp Warlock.hpp
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Make a Warlock class. It has to be in Coplien's form.
|
||||
|
||||
It has the following private attributes :
|
||||
* name (string)
|
||||
* title (string)
|
||||
|
||||
Since they're private, you will write the following getters :
|
||||
* getName, returns a reference to constant string
|
||||
* getTitle, returns a reference to constant string
|
||||
|
||||
Both these functions will have to be callable on a constant Warlock.
|
||||
|
||||
Create the following setter:
|
||||
* setTitle, returns void and takes a reference to constant string
|
||||
|
||||
Your Warlock will also have, in addition to whatever's required by Coplien's
|
||||
form, a constructor that takes, in this order, its name and title. Your Warlock
|
||||
will not be able to be copied, instantiated by copy, or instantiated without a
|
||||
name and a title.
|
||||
|
||||
For example :
|
||||
|
||||
Warlock bob; //Does not compile
|
||||
Warlock bob("Bob", "the magnificent"); //Compiles
|
||||
Warlock jim("Jim", "the nauseating"); //Compiles
|
||||
bob = jim; //Does not compile
|
||||
Warlock jack(jim); //Does not compile
|
||||
|
||||
Upon creation, the Warlock says :
|
||||
|
||||
<NAME>: This looks like another boring day.
|
||||
|
||||
Of course, whenever we use placeholders like <NAME>, <TITLE>, etc...
|
||||
in outputs, you will replace them by the appropriate value. Without the < and >.
|
||||
|
||||
When he dies, he says:
|
||||
|
||||
<NAME>: My job here is done!
|
||||
|
||||
Our Warlock must also be able to introduce himself, while boasting with all its
|
||||
might.
|
||||
|
||||
So you will write the following function:
|
||||
* void introduce() const;
|
||||
|
||||
It must display:
|
||||
|
||||
<NAME>: I am <NAME>, <TITLE>!
|
||||
|
||||
Here's an example of a test main function and its associated output:
|
||||
|
||||
int main()
|
||||
{
|
||||
Warlock const richard("Richard", "Mistress of Magma");
|
||||
richard.introduce();
|
||||
std::cout << richard.getName() << " - " << richard.getTitle() << std::endl;
|
||||
|
||||
Warlock* jack = new Warlock("Jack", "the Long");
|
||||
jack->introduce();
|
||||
jack->setTitle("the Mighty");
|
||||
jack->introduce();
|
||||
|
||||
delete jack;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
~$ ./a.out | cat -e
|
||||
Richard: This looks like another boring day.$
|
||||
Richard: I am Richard, Mistress of Magma!$
|
||||
Richard - Mistress of Magma$
|
||||
Jack: This looks like another boring day.$
|
||||
Jack: I am Jack, the Long!$
|
||||
Jack: I am Jack, the Mighty!$
|
||||
Jack: My job here is done!$
|
||||
Richard: My job here is done!$
|
||||
~$
|
||||
BIN
cpp_module_00/test
Executable file
BIN
cpp_module_00/test
Executable file
Binary file not shown.
Reference in New Issue
Block a user