Hello. They asked me to write a program, .. there is a condition, but for me it is somehow poorly understood. Here it is:

Let some device as a state contain a number from 0 to 126. At each subsequent time, the number changes according to the formula x (n + 1) = a * x (n) + b (mod127), where a = 10, b = 11. Create a class that displays this device.

The class must have member functions:

  • the constructor with the argument is the initial state,
  • function that takes the device to the next state,
  • a function that displays the status of the device.

Solved the problem, think you wrote what they ask me? Here is the code:

// List.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdio.h" #include "conio.h" #include "iostream" #include "windows.h" using namespace std; class device { public: int num; // то что содержит 0->126 device(); // Конструктор void form(); void Print(); }; device::device() // 1 констр-р с нач. знач num { cout << "Vvedi svoe znachenie: "; cin >> num; } void device::form() // 2 перевод устр. в след. сост. { this->num = (10 * this->num + 11) % 127; } void device::Print(void) // 3 вывод на экран { cout << this->num << '\n'; } void main(void) { // Создаем объект first класса device device first; first.form(); first.Print(); system("PAUSE"); } 

    1 answer 1

    x (n + 1) is the next state. it is considered in the form () method. x (n) respectively current.

    x (n + 1) = a * x (n) + b (mod127), where a = 10, b = 11. num stores the current state. that is, in the form () method, we write the formula from the condition, replacing x with num. like that:

    num = a * num + b ....

    here on the right side you use the current value, then after all operations are performed, the following is written instead of the current one. (which by the next function call will be already current)