42-cpp-module's Introduction
42-cpp-module's People
Forkers
limchanyeop42-cpp-module's Issues
CPP00 : Peer evaluation
CPP03 : Peer evaluation
CPP03 : ex02
- class FragTrap (inherits from ClapTrap)
- Name (Parameter of constructor)
- Hitpoints (100)
- Energy points (100)
- attack damage (30)
- The FragTrap class will have its construction and destruction messages.
construction/destruction chaining must be present (When you build a ScavTrap, you must start by building a ClapTrap... Destruction is in reverse order) - FragTrap will be
void highFivesGuys(void)
, display a positive high fives request on the standard output. - Extend your main function to test everything.
CPP05 : Requirements analysis
- ex00
- ex01
- ex02
- ex03
CPP03 : ex01
- class ScavTrap (inherit from ClapTrap)
- The ScavTrap class will have its construction and destruction messages.
construction/destruction chaining must be present (When you build a ScavTrap, you must start by building a ClapTrap... Destruction is in reverse order) - ScavTrap will use the attributes of Claptrap
- Name (Parameter of constructor)
- Hitpoints (100)
- Energy points (50)
- Attack damage (20)
- ScavTrap will also have a new specific function
void guardGate()
, display a message on the standard outputs to anounce that ScavTrap have enterred in Gate keeper mode.
- The ScavTrap class will have its construction and destruction messages.
CPP01 : ex03
- Make a Weapon class
- member variable
type
string
- member function
getType
method that returns a const reference to this string.- a
- member variable
- Create HumanA and HumanB class
- member variable
Weapon
classname
string
- member function
attack
method that displayNAME attacks with his WEAPON_TYPE
- member variable
- While HumanA takes the Weapon in its constructor, HumanB doesn’t.
- HumanB may not always have a Weapon, but HumanA will ALWAYS be armed.
CPP03 : ex03
- create a monster by making a Claptrap that’s half Fragtrap, half ScavTrap.
- class DiamondTrap (inherit from both the FragTrap AND the ScavTrap.)
- Its attributes and functions will be chosen from either of its parent classes:
- member variable
- Name (Parameter of constructor)
- ClapTrap::Name (Parameter of constructor + “_clap_name”)
- Htipoints (FragTrap)
- Energy points (ScavTrap)
- Attack damage (FragTrap)
- member function
- attack (ScavTrap)
- It will have the special functions of both.
- member variable
- As usual, your main will be extended to test the new class.
- a new function
void whoAmI();
that will display its name and its clapTrap name. -Wshadow
,-Wno-shadow
CPP01 : ex06
- Karen says is important or not, because sometimes we don’t want to pay attention to everything Karen says.
- Display all the info that is at this level or above it.
- example1
$> ./karenFilter "WARNING"
[ WARNING ]
I think I deserve to have some extra bacon for free.
I’ve been coming here for years and you just started working here last month.
[ ERROR ]
This is unacceptable, I want to speak to the manager now.
- example2
$> ./karenFilter "I am not sure how tired I am today..."
[ Probably complaining about insignificant problems ]
- There are many ways to filter Karen, but one of the best ones is to SWITCH her off
CPP01 : ex05
- private member functions:
void debug( void );
void info( void );
void warning( void );
void error( void );
- public member functions:
void complain( std::*string level*);
- The goal of this exercise is to use pointers to member functions.
- Without using a forest of if / elseif / else
CPP02 : ex01
- A constructor that takes a constant integer as a parameter and that converts it to
the correspondant fixed(8) point value. - A constructor that takes a constant floating point as a parameter and that converts
it to the correspondant fixed(8) point value. - A member function
float toFloat( void ) const;
that converts the fixed point
value to a floating point value. - A member function
int toInt( void ) const;
that converts the fixed point value
to an integer value. - An overload to the
<<
operator that inserts a floating point representation of the
fixed point value into the parameter output stream.
CPP02 : Peer evaluation
CPP02 : Requirements analysis
- ex00
- ex01
- ex02
- ex03
CPP06 : ex02
CPP01 : ex02
- Create a string containing "HI THIS IS BRAIN".
- Create a
stringPTR
which is a pointer to the string. - and
stringREF
which is a reference to the string. - Display the address in memory of the string.
- Display the address of the string by using
stringPTR
andstringREF
. - Display the string using the pointer.
- Display the string using the reference.
CPP00 : ex01
- 전화번호부 기능
- 프로그램이 시작하면 입력을 받는 프롬프트를 출력
- ADD, SEARCH, EXIT
- 이외의 유효하지 않은 명령은 폐기
- 프로그램은 연락처가 빈 상태로 시작
- 동적할당은 사용하지 않음
- 연락처는 8개 까지 저장되고, 9번째 입력은 가장 오래된 연락처를 대체함
- EXIT
- 종료하고 기록된 연락처를 삭제
동적할당되지 않기 때문에 메모리 문제 없음, 그냥 종료
- 종료하고 기록된 연락처를 삭제
- ADD
- 새 연락처 정보를 입력하라는 프롬프트 출력
한 번에 하나의 필드씩 모든 입력이 끝날 때 까지 입력받음
first_name
,last_name
,nickname
,phone_number
,darkest_secret
- 전화번호부는 클래스의 인스턴스로 구현
- 연락처는 클래스의 인스턴스로 구현
- 새 연락처 정보를 입력하라는 프롬프트 출력
- SEARCH
- 비어있지 않은(입력 받았던) 연락처의 정보를 출력
index
,first_name
,last_name
,nick_name
- 각 정보는 10칸의 너비를 가지고 출력
- 우측 정렬
|
로 구분- 너비를 넘어서는 문자의 경우 너비 이후의 문자는 잘라내고
.
으로 대체
- 열람하고자하는 연락처의 인덱스를 요구하는 프롬프트 출력
- 입력받은 인덱스의 정보를 한 줄에 한 field 씩 출력
- 입력받은 입력이 유효하지 않을 경우의 프로그램 행동을 정의할 것
- 비어있지 않은(입력 받았던) 연락처의 정보를 출력
- 그 외의 입력은 폐기
- 유효한 명령으로 실행될 경우, ADD or SEARCH 동작을 EXIT 가 입력될 때 까지 동작
CPP00 : ex00
- 소문자를 대문자로 바꾸는 기능
- C++ standard input, output
- input이 없을 때, * LOUD AND UNBEARABLE FEEDBACK NOISE * 출력
- input으로 들어온 argv 사이 공백 없이 연결
- 출력 마지막에 newline
CPP06 : Requirements analysis
- ex00
- ex01
- ex02
CPP04 : ex03 Interface & recap
-
C++98에는 인터페이스가 없음(C++20에도 없음), 일반적으로 순수 추상클래스 = 인터페이스
-
AMateria class
class AMateria { protected: [...] public: AMateria(std::string const & type); [...] std::string const & getType() const; //Returns the materia type virtual AMateria* clone() const = 0; virtual void use(ICharacter& target); };
- AMateria 추상 클래스를 상속받은 Ice, Cure 클래스 생성
clone()
method will return a new instance of the real Materia’s type.use(ICharacter&)
method- Ice:
"* shoots an ice bolt at NAME *"
- Cure:
"* heals NAME’s wounds *"
- replace NAME by the name of the Character given as parameter.
- Ice:
-
Character class
class ICharacter { public: virtual ~ICharacter() {} virtual std::string const * getName() const = 0; virtual void equip(AMateria* m) = 0; virtual void unequip(int idx) = 0; virtual use(int idx, ICharacter& target) = 0; }
- Character possesses an inventory of 4 Materia at most, empty at the start.
use
/unequip
a nonexistent Materia, don’t do a thing.unequip
method must NOT delete Materia!use(int, ICharacter&)
method will have to use the Materia at the idx slot,
and pass target as parameter to theAMateria::use
method.
- Your Character must have a constructor taking its
name
as a parameter.
Copy or assignation of a Character must be deep, of course.
The old Materia of a Character must be deleted. Same upon the destruction of a Character.
-
MateriaSource class
class IMateriaSource { public: virtual ~IMateriaSource() {} virtual void learnMateria(AMateria*) = 0; virtual AMateria* createMateria(std::string const & type) = 0; };
learnMateria
must copy theMateria
passed as a parameter, and store it in memory to be cloned later.
Much in the same way as for Character, the Source can know at most 4 Materia, which are not necessarily unique. (중복 스킬이 MateriaSource 슬롯에 저장될 수있다.)createMateria(std::string const &)
will return a newMateria
, which will be a copy of the Materia (previously learned by the Source) which type equals the parameter.
Returns0
if the type is unknown. (MateriaSource 내부에 매개변수로 받은 type이 없을(모를) 경우)
CPP03 : Requirements analysis
- ex00
- ex01
- ex02
- ex03
CPP04 : ex01 I don’t want to set the world on fire
- Reuse ex00 classes.
- Create Brain class.B
- contain
an array of 100 std::string idea
- contain
- Dog and cat will have a private Brain* attribute.
- Upon construction Dog and Cat will initialize their Brain* with a new Brain();
- Upon destruction Dog and Cat will delete their Brain.
- Your main will create and fill an Array of Animal half of it will be Dog and the other half will be Cat.
- Before exit, your main will loop over this array and delete every Animal. You must delete directly Cat and Dog as an Animal.
- A copy of a Cat or Dog must be "deep". Your test should show that copies are deep!
- Constructors and destructors of each class must have specifics output. The appropriate destructors must be called.
CPP01 : ex01
- Re-using the Zombie class.
- Create an horde of zombies.
- Allocates N Zombie objects.
- It must allocate all the N Zombie objects in a single allocation.
- Then, it should initialize each Zombie by giving to each one a name.
Zombie* zombieHorde( int N, std::string name );
- Calling announce() on each one of the Zombies.
- Delete ALL the Zombies when you don’t need them anymore.
CPP01 : Requirements analysis
- ex00
- ex01
- ex02
- ex03
- ex04
- ex05
- ex06
CPP04 : Requirements analysis
- ex00
- ex01
- ex02
- ex03
CPP04 : Peer evaluation
CPP06 : ex01
CPP00 : Requirements analysis
- General Rules
- ex00
- ex01
- ex02
CPP05 : ex03 At least this beats coffee-making
- Intern class
- has no name, no grade, no defining characteristics
makeForm
- takes two string
name
of a formtarget
for the form
- return
a pointer of Form
"Intern creates <form>”
- takes two string
- If it’s using a worse method, like if/elseif/elseif/else branchings, or some other ugly stuff like this, it will not be accepted during the evaluation. If the requested form is not known, print an explicit error message.
CPP01 : Peer evaluation
CPP05 : ex00 Mommy, when I grow up, I want to be a bureaucrat!
- exception classes do not need to be in orthodox canonical form.
- Bureaucrat class
- a constant name
- a grade that ranges from 1 (highest possible) to 150 (lowest possible)
- create a Bureaucrat with an invalid grade must throw an exception
Bureaucrat::GradeTooHighException
Bureaucrat::GradeTooLowException
getName
getGrade
- two functions to
increment
ordecrement
the grade. - overload of the
<<
operator- to ostream that outputs something like
<name>
, bureaucrat grade<grade>
.
- to ostream that outputs something like
- create a Bureaucrat with an invalid grade must throw an exception
CPP03 : ex00
- class ClapTrap
- private
- Name (Parameter of constructor)
- Hitpoints (10)
- Energy points (10)
- Attack damage (0)
- public
void attack(std::string const & target)
void takeDamage(unsigned int amount)
void beRepaired(unsigned int amount)
- private
- In all of these functions, you have to display something to describe what happens.
- The constructor and destructor must also display something, so people can see they have been called.
- You will provide a main function, with enough tests to demonstrate that your code is functional.
CPP04 : ex02 abstract class
- Default animal class should not be instantiable.
- The rest should work as before.
CPP05 : ex02 No, you need form 28B, not 28C...
-
ShrubberyCreationForm
- Required grades: sign 145, exec 137
- Action: Create a file called _shrubbery, and write ASCII trees inside it, in the current directory.
-
RobotomyRequestForm
- Required grades: sign 72, exec 45
- Action: Makes some drilling noises
- 50%: tell us that has been robotomized successfully
- 50%: tell us it’s a failure.
-
PresidentialPardonForm
- Required grades: sign 25, exec 5
- Action: Tells us has been pardoned by Zafod Beeblebrox.
-
All of these will have to take only one parameter in their constructor, which will represent the target of the form.
For example, "home" if you want to plant shrubbery at home. Remember the form’s attributes need to remain private, and in the base class. -
Add
execute(Bureaucrat const & executor) const
to the base form, and implement a method executing the form’saction
in all the concrete forms. -
You have to check that the form is signed, and that the bureaucrat attempting to execute the form has a high enough grade, else you will throw an appropriate exception.
Whether you want to make these checks in every concrete class or make the check-in the base class then calling another method to execute the action is up to you, but one way is prettier than the other one. In any event, the base form must be an abstract class. -
executeForm(Form const & form)
function to the bureaucrat. It must attempt to execute the form, and- if it’s a success, print something like executes .
- If not, print an explicit error message.
CPP06 : Peer evaluation
CPP05 : Peer evaluation
CPP04 : ex00 Polymorphism
- Constructors and destructors of each class must have specifics output.
- Create a simple and complete base class Animal.
- protected
- std::string type (for the animal class the type can be left empty or put at any value)
- protected
- Create a class Dog that inherits from Animal.
- Create a class Cat that inherits from Animal.
- Every class should put their name in the Type field for example:
The Dog class type must be initialized as "Dog". - Every animal must be able to use the method makeSound().
int main() {
const Animal* meta = new Animal();
const Animal* j = new Dog();
const Animal* i = new Cat();
std::cout << j->getType() << " " << std::endl;
std::cout << i->getType() << " " << std::endl;
i->makeSound(); //will output the cat sound!
j->makeSound();
meta->makeSound();
...
}
- This should output the specific makeSound of the Dog and cat class, not the animal one.
- To be sure you will create a WrongCat class that inherits a WrongAnimal class that will output the WrongAnimal makeSound() when test under the same conditions.
CPP01 : ex04
- Make a program called replace
- Takes a filename and two strings, let’s call them s1 and s2, which are NOT empty.
- It will open the file, and write its contents to FILENAME.replace, after replacing every occurrence of s1 with s2.
- All the member functions of the class std::string are allowed, except replace.
- you will handle errors as best you can.
- Do not use the C file manipulation functions.
CPP02 : ex00
- Orthodox Canonical Class Form (OCCF)
- 기본 생성자
- 기본 소멸자
- 복사 생성자
- 할당 연산자 오버로딩
- Fixed Class
- Private members:
- An interger to store the fixed point value.
- A static constant integer to store the number of fractional bits.
This constant will always be the litteral 8.
const 변수(=상수) 선언과 함께 값(리터럴)을 할당 해줘야 한다. (리터럴 표기법)
- Public members:
- A default constructor that initializes the fixed point value to 0.
- A copy constructor.
- A destructor.
- An assignation operator overload.
int getRawBits( void ) const;
void setRawBits( int const raw );
- Private members:
CPP01 : ex00
- Zombie class
- private name
announce( void )
: BraiiiiiiinnnzzzZ...- 소멸자 호출될 때, 해당 Zombie 클래스의 이름을 포함하는 메세지를 출력
Zombie* newZombie ( std::string name );
void randomChump ( std::string name );
- 좀비는 적절한 때에 소멸 (더 이상 필요하지 않을 때)
- 적절한 방식으로 할당 (스택 또는 힙)
CPP02 : ex02
- Six comparison operators :
>
,<
,>=
,<=
,==
and!=
- Four arithmetic operators :
+
,-
,*
and/
- pre-increment (
++a
), post-increment (a++
), pre-decrement (—-a
), post-decrement (a—-
) that will increment or decrement the fixed point value from the smallest repre-
sentable ε such as 1 + ε > 1. - Add the following public static member functions overloads to your class :
- The static member function min
- takes references on two fixed point values
returns a reference to the smallest value. - and an overload that takes references on two constant fixed point values
returns a reference to the smallest constant value.
- takes references on two fixed point values
- The static member function max
- takes references on two fixed point values
returns a reference to the biggest value - and an overload that takes references on two constant fixed point values
returns a reference to the biggest constant value.
- takes references on two fixed point values
- The static member function min
CPP05 : ex01 Form up, maggots!
-
Form class
- private
- constant, name
- a boolean indicating whether it is signed (at the beginning, it’s not) : default : false
- constant, a grade required to sign it
- constant, a grade required to execute it
- The grades are subject to the same constraints as in the Bureaucrat, and exceptions will be thrown if any of them are out of bounds,
Form::GradeTooHighException
andForm::GradeTooLowException
- make
getters
for all attributes - overload of the
<<
operator to ostream that completely describes the state of the form. -
beSigned
- takes a Bureaucrat
- makes the form signed if the bureaucrat’s grade is high enough.
- private
-
Bureaucrat class
-
signForm
- If the signing is successful, it will print something like
"<bureaucrat> signs <form>”
- otherwise it will print something like
"<bureaucrat> cannot sign <form> because <reason>"
- If the signing is successful, it will print something like
-
CPP06 : ex00 Scalar conversion
- Program that takes a string representation of a C++ literal value (in its most common form) as a parameter.
- This literal must belong to one of the following a scalar types: char, int, float or double. Only the decimal notation will be used.
- char:
- non displayable characters can’t be passed as a parameter to your program, and if a conversion to char is not displayable, output a notification instead.
- int: 0, -42, 42, ...
- float: 0.0f, -4.2f, 4.2f, ...
- You will also accept these pseudo literals as well, you know, for science: -inff, +inff and nanf.
- double: 0.0, -4.2, 4.2, ...
- You will also accept these pseudo literals as well, you know, for fun: -inf, +inf and nan.
./convert 0
char: Non displayable
int: 0
float: 0.0f
double: 0.0
./convert nan
char: impossible
int: impossible
float: nanf
double: nan
./convert 42.0f
char: '*'
int: 42
float: 42.0f
double: 42.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.