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.

37 thoughts on “Tasks: Data input and output

  1. for some reason some of the code is not inserted

    I'll try again

    #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;
    }

  2. Solving all three problems in one code.
    Don't judge strictly ,I'm a teapot.
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    // create nine variables to enter the user's personal data
    int name = 0;
    int surname = 0;
    int data = 0;
    int number = 0;
    char a = 0;
    char b = 0;
    char c = 0;
    char d = 0;
    char e = 0;
    // requesting data input from the keyboard
    cout <> name;
    cout << endl;
    cout <> surname;
    cout << endl;
    cout <> data;
    cout << endl;
    cout <> number;
    cout << endl;
    // display the received data on the screen
    cout << "Ваше цифровое имя: " << name << endl;
    cout << "Ваша цифровая фамилия: " << surname << endl;
    cout << "Цифровая дата твоего рождения: " << data << endl;
    cout << "Ваш личный цифровой номер: " << number << endl;
    // please enter your username character by character
    cout << "Просим ввести пятизначное слово пароль!\nYou need to enter one character at a time. In Latin!: " <> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    // display the code name on the screen
    cout << "Кодовое имя пользователя: " << a << b << c << d << e << "." << endl;
    // display the phrase on the screen
    cout << "А почему в ресторане ей никогда не нравится то,\n\nчто заказала она, and always like it, what did I order?\n\n";
    cout << "И она начинает есть у меня из тарелки. I tell her:\n\n\"Закажи себе то же самое\". She says: \"Зачем?\n\nЯ только попробовать\". И сьедает половину.\n\n";
    cout << "\t\\\\ к.ф. \"О чем говорят мужчины\"\\\\\t" << endl;
    // and now a mini calculator! Let's count the sum ,difference and product of two numbers
    // create variables of type int
    int number1 = 0;
    int number2 = 0;
    // we ask you to enter two numbers
    cout <> number1;
    cin >> number2;
    // count and display the results
    cout << "Сумма заданных чисел: " << number1 + number2 << " !" << endl;
    cout << "Разница заданных чисел: " << number1 – number2 << " !" << endl;
    cout << "Произведение заданных чисел: " << number1 * number2 << " !" << endl;

    system("PAUSE");
    return 0;

    }

  3. #include
    using namespace std;
    int main()
    { setlocale(LC_ALL, “RUS”);
    cout << "А почему в ресторане eй никогда не нравится то,"<<'\n';
    cout << "что заказала она,"<<"и всегда нравится то,"<<"что заказал я?"<<'\n';
    cout << "И она начинает есть у меня из тарелки."<< "Я ей говорю:"<<'\n';
    cout << "<>.” <<"Она говорит:"<<"Зачем?"<<'\n';
    cout <>.”<<"И съедает половину."<<'\n';
    cout << '\/' << '\/'<<"к.ф." <<"Очем говорят мужчины"<< '\/' << '\/'<<'\n'<<endl<<endl<<endl;}

  4. // project1.cpp : This file contains the function “main”. Execution of the program begins and ends here.
    //

    #include “pch.h”
    #include
    #include
    using namespace std;

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

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

    cout <> a;
    cout <> b;
    cout <> c;
    cout <> d;

    cout << endl;

    cout << "Переменная а = " << a << endl;
    cout << "Переменная b = " << b << endl;
    cout << "Переменная c = " << c << endl;
    cout << "Переменная d = " << d << endl;
    }

    //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.

Leave a Reply

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