Skip to content

Glagolev ruslan request to check homework2 - #17

Open
RuslanGlagolev wants to merge 20 commits into
masterfrom
glagolev_ruslan_homework2
Open

Glagolev ruslan request to check homework2#17
RuslanGlagolev wants to merge 20 commits into
masterfrom
glagolev_ruslan_homework2

Conversation

@RuslanGlagolev

Copy link
Copy Markdown
Collaborator

No description provided.

@MykolaSuperman MykolaSuperman left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У вас не все дз выполненые, у вас не решенно последняя задача из дз Лучший делитель

Comment thread HomeWork2/Glagolev_Ruslan_task1.cpp Outdated
int main() {
int n;
int sum = 0;
int i = 0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давайте будем приучаться давать переменным более читабельные имена)
например ну сложно понять что означает n? я думаю что лучше будет написать number
или например i думаю что лучше будет написать count_digit_in_number

Comment thread HomeWork2/Glagolev_Ruslan_task1.cpp Outdated
n /= 10;
i++;
}
double avarage = (double)sum / (double)i;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

смотрите не нужно явно преобразовывать оба выражения к double, достаточно хотябы чтобы один из аргументов делителя был вещественного типа.
И потом не используйте С стиль приведения типов, используйте только С++ стиль std::static_cast
Т.е. лучше было бы так

 double avarage = sum / std::static_cast<double>(i);

Comment thread HomeWork2/Glagolev_Ruslan_task1.cpp Outdated
int sum = 0;
int i = 0;

std::cout << "please, enter n = ";

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

потом пишите в cout что будет делать ваша программа, т.е. сделайте вывод на экран

Comment thread HomeWork2/Glagolev_Ruslan_task2.cpp Outdated
int n;
int first = 0;
int second = 0;
int i = 0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как и выше назовите более читабельней имена переменных

Comment thread HomeWork2/Glagolev_Ruslan_task2.cpp Outdated
int first = 0;
int second = 0;
int i = 0;
std::cout << "Please enter number type ******" << std::endl;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

опишите пользователю что делает ваша программа, а то просто сложно понять зачем вводить какое то число

Comment thread HomeWork2/Glagolev_Ruslan_task3.cpp Outdated
int s = 1;
int f = 0;
std::cout << "enter ***" << std::endl;
std::cin >> n;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тоже замечание как и выше

Comment thread HomeWork2/Glagolev_Ruslan_task3.cpp
Comment thread HomeWork2/Glagolev_Ruslan_task4.cpp Outdated

int main() {
int s = 0;
int a;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тип переменной s должен быть больше чем тип переменной a, т.к. у вас может быть переполнение

Comment thread HomeWork2/Glagolev_Ruslan_task4.cpp Outdated

int main() {
int s = 0;
int a;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

потом зачем тут обьявлять переменную a ?
обьявите ее прям в цикле for, ограничивайте область видимости переменным

Comment thread HomeWork2/Glagolev_Ruslan_task4.cpp

@MykolaSuperman MykolaSuperman left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пожалуйста примените к части кода
https://zed0.co.uk/clang-format-configurator/

Comment thread HomeWork2/Glagolev_Ruslan_task4.cpp
Comment thread HomeWork2/Glagolev_Ruslan_task5.cpp
Comment thread HomeWork2/Glagolev_Ruslan_task6.cpp
Comment thread HomeWork2/Glagolev_Ruslan_task2.cpp
Comment thread HomeWork2/Glagolev_Ruslan_task3.cpp Outdated
int normal_number;
int check_number;
int multiplicity_of_number = 1;
int reverse_number = 0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тип reverse_number должен быть больше типа int, так как вы переворачиваете число, соотсветвенно оно может больше чем тип int, точнее быть в него не может поместиться

Comment thread HomeWork2/Glagolev_Ruslan_task4.cpp Outdated
if (number % 2 != 0) {
sum += number;
} else {
number = 0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем тут обнулять переменную? она все равно дальше по коду не будет использоваться

Comment thread HomeWork2/Glagolev_Ruslan_task4.cpp
Comment thread HomeWork2/Glagolev_Ruslan_task4.cpp Outdated
--max_iteration;
} else {
std::cout << "Enter number " << number_of_digits << ":" << std::endl;
std::cin >> number;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вообще бесмысленный else {
у вас все равно будет начало цикла где вы будете просить ввод заново числа
я думаю что вам этот else нужно просто удалить

Comment thread HomeWork2/Glagolev_Ruslan_task5.cpp
Comment thread HomeWork2/Glagolev_Ruslan_task5.cpp Outdated
std::cout << "Enter tour number- ";
std::cin >> number;
for (long long i = 1; i <= number; i++) {
if (number % i == 0 && i != number) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

удалите i != number число должно само на себя делиться

Comment thread HomeWork2/Glagolev_Ruslan_task5.cpp Outdated
std::cout << "This program calculates the best divisor of your number.\n";
std::cout << "Enter tour number- ";
std::cin >> number;
for (long long i = 1; i <= number; i++) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size_t ?

Comment thread HomeWork2/Glagolev_Ruslan_task6.cpp
Comment thread HomeWork2/Glagolev_Ruslan_task6.cpp Outdated

int main() {
int number;
int b = 0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

что такое b ?

@MykolaSuperman MykolaSuperman left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

прочитайте внимательно замечания по обьявлению переменных. И когда вы исправляете замечания, или прочитали рекомендации нажимайте кнопку Resolve conversation

int main() {
int number;
int first_half_of_the_number = 0;
int second_half_of_the_number = 0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

обьявляйте переменные по мере их использования, вот зачем тут обьявлять переменные first_half_of_the_number и second_half_of_the_number если реально они будут применяться только после того как вы проверите коректность введенного числа, т.е. проверка что число содержит 6 цифр

std::cout << "This program reverses the digits of your number in places.\n";
std::cout << "Enter your number-";
std::cin >> normal_number;
check_number = abs(normal_number);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот например тут, зачем вверху обьявлять переменную check_number а тут ей присваивать значение почему нельзя сделать сразу
int check_number = abs(normal_number)

long long best_sum_number_divisor = 0;
long long sum_number_divisor = 0;
long long divisor_1;
long long best_divisor;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот зачем обьявлять все тут переменные??? как думаете удобно смотреть весь список переменных в начале, а потом искать по всему коду где же они применяються. Приучайтесь создавать переменные(обьявлять), перед первым их использованием. Не надо все переменные создавать в начале, а потом ниже в коде их инициализировать, так никто не пишет

if (divisor < i) {
divisor = i;
}
divisor_1 = divisor;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

например зачем выносить в начале main обьявление переменной divisor_1, если она реально используеться только внутри цикла. Т.е. это плохо когда вы увеличиваете скоп переменной, когда ее скоп реально есть только тело цикла. Это плохо для читабельности кода

std::cout << "based on the sum of the divisor.\n";
std::cout << "Enter tour number- ";
std::cin >> number;
for (long long i = 1; i <= number; ++i) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вместо типа long long в цикле лучше писать size_t

std::cout << "Enter the correct number- ";
std::cin >> number;
}
for (int a = 0; a != (number + 1) / 2; a++) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вместо int привыкайте использовать size_t, и только в редких случаях пишите int


int main() {
int number;
int skimmer = 0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

название переменной огонь)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants