one implementation of the exam

This commit is contained in:
hugogogo
2022-12-01 15:47:19 +01:00
parent 16dcd06da6
commit c91d23a5d4
43 changed files with 925 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
#include "Warlock.hpp"

35
cpp_module_00/Warlock.hpp Normal file
View 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

Binary file not shown.

17
cpp_module_00/main.cpp Normal file
View 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);
}

View 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

Binary file not shown.