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. If the last task to select even and odd numbers, the arithmetic mean is wrong, why is that?


    #include
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, "rus");
    int number1 = 0;
    int number2 = 0;

    cout <> number1;
    cin >> number2;

    cout << " Сумма чисел = " << number1 + number2 << endl;
    cout << " Разность чисел = " << number1 - number2 << endl;
    cout << " Произведение чисел = " << number1 * number2 << endl;
    cout << " Среднее арифметическое чисел = " << (number1 + number2) / 2 << endl;

    system("pause");
    return 0;
    }

    1. because if you enter for example 4 and 3, then the arithmetic mean = 3,5.
      int – whole numbers

      1. Not this way!
        integer division casts fractional balances: (3+4)/2=3
        And everything works correctly! ;-)

  2. The fourth task

    #include
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_CTYPE, "rus");
    cout << "Приложение считает произведение 2х чисел, а так же сумму,разницу и среднее арифметическое\n\n";
    float a, b, c, d, e, f;
    cout <> a;
    cout <> b;

    c = a * b;//Произведение чисел
    cout << "Произведение чисел равно: " << c << "\n";
    d = a + b; // Сумма чисел
    cout << "Сумма чисел равна: " << d << "\n";
    e = a - b;// Разница чисел
    cout << "Разница чисел равна: " << e << "\n";
    f = (a + b)/2;
    cout << "Срежнее арифметическое этих двух чисел равно: " << f << "\n";

    system("pause");
    return 0;
    }

  3. setlocale does not work(LC_ALL,”rus”), I tried to write “Russian” etc,does not work

    1. It depends on you have installed the operating system.

      But in general, Windows – great stuff for teaching programming.
      Install Linux, at least in a virtual machine, and learn C ++ without the headaches.

  4. My 4 with the characters after the decimal point

  5. # include
    using namespace std;
    int main ()
    {
    setlocale (0, “”);
    int a = 3, b = 4;
    cout << a * b <<' ' << a + b << ' ' << a – b << ' ' << (a + b)/2 <<'\n';
    system ("pause");
    return 0;
    }
    I have not yet summed setlocale (0, "") for Cyrillic

  6. // alternately displays each variable.

    #include “stdafx.h”
    #include
    #include
    #include

    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “”);
    double a;
    int b;
    char c;
    string p;
    cout << "введите целое число=" <> b;
    cout << "введите вещественное число=" <> a;
    cout << "введите символ=" <> c;
    cout << "введите строку=" <> p;

    cout << "целое=" << b << endl;
    Sleep(500);
    cout << "вещественное=" << a << endl;
    Sleep(500);
    cout << "символ=" << c << endl;
    Sleep(500);
    cout << "строка=" << p << endl;
    Sleep(500);

    system("pause");

    return 0;
    }

  7. crayon-625005b3b8dd4405467011/

    #include
    #include
    using namespace std;

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

    int a = 0;
    int b = 0;

    cout << "Показать на экране произведение введенных двух чисел, "Show on the screen the product of the entered two numbers, "Show on the screen the product of the entered two numbers. " << endl;
    cout << "Введите два числа " <> a >> b;

    cout << "Вы ввели: " << a << " и "<< b << endl;

    cout << "Произведение двух чисел равно: " << a * b << endl;
    cout << "Сумма двух чисел равна: " << a + b << endl;
    cout << "Разница двух чисел равна: " << a – b << endl;
    cout << "Среднее арифметическое число введенных двух чисел: " << (a + b) / 2 << endl;

    cout << endl;

    return 0;
    }

Leave a Reply

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