Homework 1: task 1
This commit is contained in:
parent
12724d8307
commit
939fdd28f2
68
Hw1/task1.cpp
Normal file
68
Hw1/task1.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Student
|
||||
{
|
||||
uint number;
|
||||
string first_name;
|
||||
string second_name;
|
||||
|
||||
public:
|
||||
Student(uint num, string first, string second)
|
||||
{
|
||||
number = num;
|
||||
first_name = first;
|
||||
second_name = second;
|
||||
}
|
||||
|
||||
uint first_var(uint num_of_vars)
|
||||
{
|
||||
if (num_of_vars == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return number % num_of_vars;
|
||||
}
|
||||
uint second_var(uint num_of_vars)
|
||||
{
|
||||
if (num_of_vars == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (uint)first_name.front() % num_of_vars;
|
||||
}
|
||||
uint third_var(uint num_of_vars)
|
||||
{
|
||||
if (num_of_vars == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (uint)second_name.front() % num_of_vars;
|
||||
}
|
||||
|
||||
void print_name () {
|
||||
cout << number << ". " << first_name << " " << second_name << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
uint num_of_vars = 6;
|
||||
cout << "Вариантов: " << num_of_vars << "\n";
|
||||
|
||||
Student a = Student(3, "Алексей", "Хвойный");
|
||||
a.print_name();
|
||||
cout << "Первый тип варианта: " << a.first_var(num_of_vars) << "\n";
|
||||
cout << "Второй тип варианта: " << a.second_var(num_of_vars) << "\n";
|
||||
cout << "Третий тип варианта: " << a.third_var(num_of_vars) << "\n";
|
||||
|
||||
Student b = Student(4, "Иван", "Олегович");
|
||||
b.print_name();
|
||||
cout << "Первый тип варианта: " << b.first_var(num_of_vars) << "\n";
|
||||
cout << "Второй тип варианта: " << b.second_var(num_of_vars) << "\n";
|
||||
cout << "Третий тип варианта: " << b.third_var(num_of_vars) << "\n";
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue