The basics of programming in c++ for beginners

Tasks: Data input and output

In a previous articleData output on the screen and in theentray data from the keyboard We examined in detail this topic. It's time to practice – because we have a lot of work, to develop certain skills, needed a programmer and develop their logical thinking quietly.

1. Create 4 variables with different types of data and ask the user to enter values ​​in them. After entering the, display them on the screen.

2. Create 5 variables of type char, ask the user to enter a word of five letters, and show these symbols (the word) the screen. (Enter characters in Latin, tk. cyrillic is displayed incorrectly. Why? This will be discussed in one of our next lessons)

3. Display the text in this form:

data display

4. The user must enter 2 numbers. You need to show on the screen the product of these numbers, sum and difference. Show the same arithmetic mean of these numbers entered.


Questions to ask in the comments.

74 thoughts on “Tasks: Data input and output

  1. #include

    using namespace std;

    int main() {
    setlocale(0, “RU”);
    int finput, sinput;
    cout <> finput >> sinput;
    cout << "Произведение чисел: " << finput * sinput << endl;
    cout << "Сумма чисел: " << finput + sinput << endl;
    cout << "Разность чисел: " << finputsinput << endl;
    cout << "Среднее арифметическое: " << (finput + sinput) / 2;
    return 0;
    }

  2. #include
    using namespace std;
    int main(){
    int chislo1;
    int chislo2;
    cout <> chislo1;
    cout <> chislo2;

    cout << "number1 + number2 = " << chislo1 + chislo2 << endl;
    cout << "number1 – number2 = " << chislo1chislo2 << endl;
    cout << "number1 * number2 = " << chislo1*chislo2 << endl;
    cout << "srednee arifmeticheskoe = " << (double)(chislo1 + chislo2) / 2 << endl;

    cin.get();
    cin.get();
    return 0;

    }

  3. // Create 4 переменные с разными типами данных и
    // предложите пользователю ввести в них значения.
    // After entering the, display them on the screen.

    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);

    int whole;
    float reAl;
    short whole2;
    char symbol;

    cout << "Введите целое число: " <>whole;
    cout << "Введите вещественное число: " <> reAl;
    cout << "Введите целое число: " <> whole2;
    cout << "Введите один любой символ: " <> symbol;

    cout << "Целое: " << whole << ", Вещественное: " << reAl << ", Целое: " << whole2 << ", Символьное: " << symbol << ".";

    return 0;
    }

  4. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);

    int number1 = 0; int number2 = 0;
    int composition = 0; int sum = 0; int difference = 0;
    int average = 0;

    cout << "Введите первое число: " <> number1;
    cout << "Введите второе число: " <> number2;

    // Произведение двух чисел
    composition = number1 * number2;
    cout << "Произведение двух чисел – " << composition << endl;

    // Сумма двух чисел
    sum = number1 + number2;
    cout << "Сумма двух чисел – " << sum << endl;

    // Разница двух чисел
    difference = number1 – number2;
    cout << "Разница двух чисел – " << difference << endl;

    // Среднее арифметическое значение
    average = sum / 2;
    cout << "Среднее арифметическое значение – " << average << endl;

    return 0;
    }

  5. #include
    using namespace std;

    void main() {

    setlocale(LC_ALL, “RUS”);

    int a;
    char b;
    double c;
    bool d;

    cout << "Введите 1 number: " <> a;

    cout << "Введите 2 number: " <> b;

    cout << "Введите 3 number: " <> c;

    cout << "Введите 4 number: " <> d;

    cout << endl << endl << endl;

    cout << "Первое число: " << a << endl <<
    "Второе число: " << b << endl <<
    "3-ти число: " << c << endl <<
    "4-ти число: " << d << endl;

    }

  6. char a, b, c, d, i;

    cout << "Ввести слово из пяти букв: " <> a >> b >> c >> d >> i;

    cout << endl << endl << endl;

    cout << "ВЫ ВВЕЛИ: " << a << b << c << d << i << endl;

  7. #include
    using namespace std;

    void main() {

    setlocale(LC_ALL, “RUS”);

    int a, b, c;
    cout << " Введите 2 number: " <> a >> b;
    cout << "Произведение этих чисел: " << a << b << endl << endl;

    cout << "Cреднее арифметическое этих введенных чисел. " << endl;
    cout << "Сложение: " << a + b << endl;
    cout << "Умножение: " << a * b << endl;
    cout << "Вычитание: " << a – b << endl;
    cout << "Деление: " << (float)a / b << endl;
    }

  8. 1.
    #include

    using namespace std;

    int main() {

    char a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    cout << a << b << c << d << e;

    }

Leave a Reply

Your email address will not be published. Required fields are marked *