This repository has been archived by the owner on Jul 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
HW by Valery Myrzin #2
Open
waleramir
wants to merge
4
commits into
AufarLIRS:master
Choose a base branch
from
waleramir:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef RESIZE_H | ||
#define RESIZE_H | ||
char* resize(char* str, unsigned size, unsigned new_size) | ||
#endif // RESIZE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "ResizeFunc.h" | ||
|
||
char *resizenew(char *str, unsigned size, unsigned new_size) { | ||
if (new_size < size) | ||
return nullptr; | ||
auto *temp = new char[new_size]; | ||
for (unsigned i = 0; i < size; i++) { | ||
temp[i] = str[i]; | ||
} | ||
delete[] str; | ||
return temp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef RESIZE_H | ||
#define RESIZE_H | ||
char *resizenew(char *str, unsigned size, unsigned new_size); | ||
#endif // RESIZE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "StrcatFunc.h" | ||
|
||
void strcatvoid(char *to, const char *from) { | ||
while (*to) | ||
to++; | ||
while (*from) { | ||
*to = *from; | ||
to++; | ||
from++; | ||
} | ||
*to = '\0'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef STRCATFUNC_H | ||
#define STRCATFUNC_H | ||
void strcatvoid(char *to, const char *from); | ||
#endif // STRCATFUNC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "User.h" | ||
|
||
User::User(int age, QString name) { | ||
this->age_ = age; | ||
this->name_ = name; | ||
} | ||
QString User::getName() const { return name_; } | ||
int User::getAge() const { return age_; } | ||
size_t User::getCount() { return users_.size(); } | ||
void User::addUser(User user) { users_.push_back(user); } | ||
void User::removeUserAt(int index) { users_.erase(users_.begin() + index); } | ||
void User::removeUserByName(QString name) { | ||
users_.erase( | ||
std::remove_if(users_.begin(), users_.end(), | ||
[&](User found) { return found.getName() == name; }), | ||
users_.end()); | ||
} | ||
std::vector<QString> User::getAllNames() { | ||
std::vector<QString> list; | ||
std::for_each(users_.begin(), users_.end(), | ||
[&](User found) { list.push_back(found.getName()); }); | ||
return list; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef USER_H | ||
#define USER_H | ||
#include <QString> | ||
#include <vector> | ||
|
||
class User { | ||
int age_; | ||
QString name_; | ||
static std::vector<User> users_; | ||
|
||
public: | ||
User(int age, QString name); | ||
QString getName() const; | ||
int getAge() const; | ||
static size_t getCount(); | ||
static void addUser(User user); | ||
static void removeUserAt(int index); | ||
static void removeUserByName(QString name); | ||
static std::vector<QString> getAllNames(); | ||
}; | ||
#endif // USER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,58 @@ | ||
#include "mainwindow.h" | ||
#include "ResizeFunc.h" | ||
#include "StrcatFunc.h" | ||
#include "User.h" | ||
#include "ui_mainwindow.h" | ||
#include <QDebug> | ||
#include <QMessageBox> | ||
|
||
|
||
MainWindow::MainWindow(QWidget *parent) | ||
: QMainWindow(parent) | ||
, ui(new Ui::MainWindow) | ||
{ | ||
ui->setupUi(this); | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
delete ui; | ||
: QMainWindow(parent), ui(new Ui::MainWindow) { | ||
ui->setupUi(this); | ||
} | ||
|
||
|
||
class User{ | ||
int age_; | ||
QString name_; | ||
public: | ||
static std::vector<User> users_; | ||
User(int age, QString name){ | ||
this->age_=age; | ||
this->name_=name; | ||
} | ||
QString getName(){ | ||
return name_; | ||
} | ||
int getAge(){ | ||
return age_; | ||
} | ||
static size_t getCount(){ | ||
return users_.size(); | ||
} | ||
static void addUser(User user){ | ||
users_.push_back(user); | ||
} | ||
static void removeUserAt(int index){ | ||
users_.erase(users_.begin() + index); | ||
} | ||
static void removeUserByName(QString name){ | ||
users_.erase(std::remove_if(users_.begin(), users_.end(),[&](User found){return found.getName() == name;}), users_.end()); | ||
} | ||
static std::vector<QString> getAllNames(){ | ||
std::vector<QString> list; | ||
std::for_each(users_.begin(),users_.end(),[&](User found){list.push_back(found.getName());}); | ||
return list; | ||
} | ||
}; | ||
MainWindow::~MainWindow() { delete ui; } | ||
|
||
std::vector<User> User::users_; | ||
|
||
void MainWindow::on_submitPushButton_clicked() | ||
{ | ||
qDebug() << "User clicked on submit button"; | ||
|
||
|
||
User::addUser(User(22,"Timofey")); | ||
User::addUser(User(33,"Aufar")); | ||
User::addUser(User(44,"Valery")); | ||
User::addUser(User(55,"Kirill")); | ||
User::addUser(User(66,"Artem")); | ||
User::addUser(User(77,"Camila")); | ||
|
||
qDebug() << "Current students' count: " << User::getCount(); | ||
qDebug() << "All students: "; | ||
qDebug() << User::getAllNames(); | ||
qDebug() << "Removing user at 4 index"; | ||
|
||
User::removeUserAt(4); | ||
|
||
qDebug() << "Current Students' Count: " << User::getCount(); | ||
qDebug() << "All students: "; | ||
qDebug() << User::getAllNames(); | ||
qDebug() << "Removing user named Aufar "; | ||
|
||
User::removeUserByName("Aufar"); | ||
|
||
qDebug() << "Current Students' Count: " << User::getCount(); | ||
qDebug() << "All students: "; | ||
qDebug() << User::getAllNames(); | ||
void MainWindow::on_submitPushButton_clicked() { | ||
qDebug() << "User clicked on submit button"; | ||
|
||
User::addUser(User(22, "Timofey")); | ||
User::addUser(User(33, "Aufar")); | ||
User::addUser(User(44, "Valery")); | ||
User::addUser(User(55, "Kirill")); | ||
User::addUser(User(66, "Artem")); | ||
User::addUser(User(77, "Camila")); | ||
|
||
qDebug() << "Current students' count: " << User::getCount(); | ||
qDebug() << "All students: "; | ||
qDebug() << User::getAllNames(); | ||
qDebug() << "Removing user at 4 index"; | ||
|
||
User::removeUserAt(4); | ||
|
||
qDebug() << "Current Students' Count: " << User::getCount(); | ||
qDebug() << "All students: "; | ||
qDebug() << User::getAllNames(); | ||
qDebug() << "Removing user named Aufar "; | ||
|
||
User::removeUserByName("Aufar"); | ||
|
||
qDebug() << "Current Students' Count: " << User::getCount(); | ||
qDebug() << "All students: "; | ||
qDebug() << User::getAllNames(); | ||
|
||
auto a = User(666, "Devil"); | ||
qDebug() << a.getName() + "\'s Age:" << a.getAge(); | ||
|
||
char char1[12] = "First"; | ||
char char2[] = "Second"; | ||
qDebug() << char1; | ||
qDebug() << char2; | ||
strcatvoid(char1, char2); | ||
qDebug() << "Super Deep Cat Func Check starting..."; | ||
qDebug() << char1; | ||
if (strcmp(char1, "FirstSecond") == 0) | ||
qDebug() << "Test passed"; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Забыли заинклудить хедер-файл. Здесь - не критично, потому что хедер сам не инклудит ничего, но лучше сразу привыкать к хорошему.