Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- class Question
- {
- char* name;
- char answer;
- int index;
- int points;
- void Free();
- void CopyFrom(const Question& other);
- public:
- Question();
- Question(const char* name, char answer, int index, int points);
- Question(const Question& other);
- Question& operator=(const Question& other);
- ~Question();
- void setIndex(int index);
- void setPoints(int points);
- void setAnswer(char answer);
- };
- void Question::Free()
- {
- delete[] name;
- answer = '\0';
- index = 0;
- points = 0;
- }
- void Question::CopyFrom(const Question& other)
- {
- int len1 = strlen(other.name);
- name = new char[len1 + 1];
- strcpy(name, other.name);
- answer = other.answer;
- index = other.index;
- points = other.points;
- }
- Question::Question()
- {
- name = nullptr;
- answer = '\0';
- index = 0;
- points = 0;
- }
- Question& Question::operator=(const Question& other)
- {
- if (this != &other)
- {
- Free();
- CopyFrom(other);
- }
- return *this;
- }
- Question::Question(const Question& other)
- {
- CopyFrom(other);
- }
- Question::~Question()
- {
- Free();
- }
- Question::Question(const char* name, char answer, int index, int points)
- {
- int len = strlen(name);
- this->name = new char[len + 1];
- strcpy(this->name, name);
- setAnswer(answer);
- setIndex(index);
- setPoints(points);
- }
- void Question::setPoints(int points)
- {
- if (points<0)
- {
- points = 0;
- }
- this->points = points;
- }
- void Question::setIndex(int index)
- {
- if (index<1)
- {
- index = 1;
- }
- this->index = index;
- }
- void Question::setAnswer(char answer)
- {
- if (answer<'a' || answer>'z')
- {
- answer = 'a';
- }
- this->answer = answer;
- }
- class Test
- {
- char* name;
- Question* questions;
- int questionsSize;
- int count;
- void Free();
- void CopyFrom(const Test& other);
- public:
- Test(int questionsCount);
- Test(const Test& other);
- ~Test();
- Test& operator=(const Test& other);
- bool addQuestion(const Question& q)
- };
- void Test::Free()
- {
- delete[] name;
- delete[] questions;
- }
- void Test::CopyFrom(const Test& other)
- {
- int len1 = strlen(other.name);
- name = new char[len1 + 1];
- strcpy(name, other.name);
- questions = new Question[other.questionsSize];
- questionsSize = other.questionsSize;
- count = other.count;
- for (int i = 0; i < count; i++)
- {
- questions[i] = other.questions[i];
- }
- }
- Test::Test(int questionsCount)
- {
- questions = new Question[questionsCount];
- questionsSize = questionsCount;
- count = 0;
- }
- Test::Test(const Test& other)
- {
- CopyFrom(other);
- }
- Test::~Test()
- {
- Free();
- }
- Test& Test::operator=(const Test& other)
- {
- if (this != &other)
- {
- Free();
- CopyFrom(other);
- }
- return *this;
- }
- bool Test::addQuestion(const Question& q)
- {
- if (count == questionsSize)
- return false;
- questions[count] = q;
- count++;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement