The basics of programming in c++ for beginners

Tasks: Data types, variables and constants

Here are collected the task to the article Data types, variables and constants. Try to solve problems on their own and only need to look at the decision. So you will learn much faster programming fundamentals.

1. Declare variables with which you can calculate the total amount of the purchase of several products. For example a chocolate bar, coffee and packets of milk.

2. Declare three variables of type int, and the first to assign a numeric value, the second variable is the first variable increased by 3, and the third variable is equal to the sum of the first two.

3. Declare variables, to count the total number of objects for the table. for example cups, the same number of saucers and spoons.

126 thoughts on “Tasks: Data types, variables and constants

  1. #include
    using namespace std;
    int main()
    {
    int chocolate, coffe;
    int milk, summ;

    chocolate = 50;
    coffee = 100;
    milk = 65;

    cout << "Шоколад " << chocolate << " руб." <<'\n';
    cout << "Кофе " << coffe << " руб." <<'\n';
    cout << "Молоко " << milk << " руб." <<'\n';

    summ = chocolate + coffe + milk;
    cout << "Сумма всех товаров: " << summ << " руб." <<'\n';

    return 0;

    }

    1. #include
      #include
      using namespace std;

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

      int chocolate, milk, coffee;
      int summ;
      chocolate = 75;
      milk = 25;
      kofe = 50;

      summ = milk + coffee + chocolate;
      cout << "шоколад – 75 р\nмолоко – 25 р\nкофе – 50 _" << endl;
      cout << "общая сумма = "<<summ<<" р";

      return 0;
      }

  2. vector products;
    vector price;
    float a;
    int count;
    int coutn_product;
    cout <> count;
    products.resize(count);
    price.resize(count);
    for (int i = 0; i < products.size(); i )
    {
    cout << "Количество товара #" << i <> coutn_product;
    products[i] = coutn_product;
    }
    for (int i = 0; i < price.size(); i )
    {
    cout << "Цена за 1 шт. товара #" << i <> a;
    price[i] = a;
    }
    for (int i = 0; i < count; i )
    {
    summ += products[i] * price[i];
    }
    cout << summ;

  3. setlocale(LC_ALL, “rus”);
    int chocolate, coffee;
    int milk, summ;

    chocolate = 50; //цена
    coffee = 100; //цена
    milk = 75; //цена
    int ammount_chocolate, ammount_coffee;
    int ammount_milk;

    ammount_chocolate = 3;//количество
    ammount_coffee = 3;//количество
    ammount_milk = 3;//количество

    cout << "Шоколад" << chocolate << "руб " << ammount_chocolate << "x" << endl;
    cout << "Кофе" << coffee << "руб " << ammount_coffee << "x" << endl;
    cout << "Молоко" << milk << "руб " << ammount_milk << "x" << endl;

    summ = (chocolate * ammount_chocolate) + (milk * ammount_milk) + (coffee * ammount_coffee);

    cout << summ;

  4. #include

    using namespace std;

    int main()
    {

    setlocale(LC_ALL, “Russian”);

    int choco, cofe, milk, sum;

    cout <> choco;

    cout <> cofe;

    cout <> milk;

    summa = (choco * 56) + (cofe * 50) + (milk * 182);

    cout << "\nВыши покупки обошлись вам в: " << sum << " руб.";
    }

    1. #include

      using namespace std;

      int main()
      {

      setlocale(LC_ALL, “Russian”);

      int choco, cofe, milk, sum;

      cout <> choco;

      cout <> cofe;

      cout <> milk;

      summa = (choco * 56) + (cofe * 50) + (milk * 182);

      cout << "\nВыши покупки обошлись вам в: " << sum << " руб.";
      }

  5. #include

    using namespace std;

    int main()
    {

    setlocale(LC_ALL, “Russian”);

    int a, b, c;

    cout << "Вы вводите первое чилсо, а второе число будет увеличино на 3, затем третие число будет ровняться сумме двух чисел.\n";

    cout <> a;

    b = a * 3;
    c = a + b;

    cout << "Первое число равняется: " << a << "\n";
    cout << "Второе число равняется: " << b << "\n";
    cout << "Сумма двух чисел равняется: " << c << "\n";
    }

  6. #include

    using namespace std;

    int main()
    {

    setlocale(LC_ALL, “Russian”);

    int cups, saucers, spoons, all;

    cout <> cups;

    cout <> saucers;

    cout <> spoons;

    all = cups + saucers + spoons;

    cout << "\nУ вас общего количества предметов для сервировки стола ровняется: " << all;
    }

  7. Answer to 1 the task:
    #include
    #include
    using namespace std;
    int main () {
    setlocale(LC_ALL, “Russian”);
    int choco, coffe, milk, result;
    cin >> choco >> coffe >> milk;
    result = (choco + coffe + milk);
    cout << "Общая сумма всех продуктов: " << result << endl;
    return 0;
    }

  8. Answer to 2 the task:
    #include
    using namespace std;
    int main () {
    int a = 11;
    int b = a + 3;
    int c = a + b;
    cout << "Result A: " << a << endl;
    cout << "Result B: " << b << endl;
    cout << "Result C: " << c << endl;
    return 0;
    }

Leave a Reply

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