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
    #include
    #include
    using namespace std;
    int main()
    {
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    int coffe, milk, chocolate;
    cout << "Введите кол-во " <> coffe;
    cout <<"Кол-во кофе "<< coffe << endl;
    cout << "Введите кол-во " <> milk;
    cout <<"Кол-во "<< milk << endl;
    cout <> chocolate;
    cout <<"Кол-во шоколада "<< chocolate << endl;
    cout << "——————————-" << endl;
    float PriceCoffe, PriceMilk, PriceCholocate;
    cout << "цена кофе " <> PriceCoffe;
    cout <<"Цена кофе " <<PriceCoffe << endl;
    cout << "Цена молока" <> PriceMilk;
    cout << "Ценв молока "<<PriceMilk << endl;
    cout << "Цена шоколада " <> PriceCholocate;
    cout << "Цена шоколада "<<PriceCholocate << endl;
    float sum = 0;
    sum = (coffe * PriceCoffe) + (milk * PriceMilk) + (chocolate * PriceCholocate);
    cout << "Общая стоимость = ";
    cout << coffe * PriceCoffe << "+" << milk * PriceMilk << "+" << chocolate * PriceCholocate << "=" << sum << endl;

    }

  2. #include

    using namespace std;

    int main (){
    int chokolate = 30;
    int milk = 20;
    int coffe = 12;

    cout << "sum chololate, milik, coffee = " << chocolate + milik + coffe << endl;
    }

    :D

  3. #include
    #include
    using namespace std;

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

    int kol_posit = 0;
    int vilki = 1;
    int tar_milk = 1;
    int tar_glub = 1;
    int logki = 1;
    int chashki = 1;
    int itogo = 0;
    cout <> kol_posit;
    vilki = vilki * kol_posit;
    logki = logki * kol_posit;
    tar_glub = tar_glub * kol_posit;
    tar_milk = tar_milk * kol_posit;
    chashki = chashki * kol_posit;
    cout << "вам потребуется \n";
    cout << "вилок " << wolves << endl;
    cout << "ложек " << Log << endl;
    cout << "глубоких тарелок " << tar_glub << endl;
    cout << "мелких тарелок " << takes_milk << endl;
    cout << "чашек " << chashki << endl;
    itogo = fork + takes_milk + tar_glub + Log + chashki;
    cout << "итого понадобится " << itogo << " предметов";
    return 0;

    }

    1. #include
      #include
      #include

      using namespace std;

      int main() {

      setlocale(LC_ALL, “RU”);

      int milk, coffe, chocolate, result;
      cout <> milk;
      cout <> coffe;
      cout <> chocolate;
      result = milk + coffe + chocolate;
      cout << milk << "+" << coffe << "+" << chocolate << "=" << result << endl;

      return 0;

      }

  4. #include

    using namespace std;

    int star = 25;
    int bludce = 0;
    you are logical = 0;

    int sum;

    int main()
    {
    setlocale(LC_ALL, “Rus”);
    if (bludce <= stars){
    bludce += 1;
    }

    if (tallow <= stars) {
    oil += 1;
    }

    if (lojka = chaska) {
    if (bludce = chaska) {
    cout << "Количество приборов на столе поровну" << endl;
    sum = star + tallow + bludce;
    cout << "Общая сумма: " << sum << " предметов" << endl;
    }
    }
    return 0;
    }

  5. #include

    using namespace std;

    int main()
    {
    int a = 10;
    int b = a + 3;
    int c = a + b;
    setlocale(LC_ALL, “rus”);
    cout << "Введите значение для первой переменной: \n";
    cout << "\t1 переменная: " << a << endl;
    cout << "\t2 переменная: " << b << endl;
    cout << "\t3 переменная: " << c << endl;

    return 0;
    }

  6. int Counter{};
    int Titles_Counter{};
    char **Titles{nullptr};
    bool Get_Price(float &price, char prod_name[])
    {
    double units{};
    double unit_price{};

    if (Counter > Titles_Counter – 1)
    return false;

    cout << "——————————" << endl;
    cout << "Name of Product: " << prod_name << endl;
    cout <> units;
    cout <> unit_price;
    price = units * unit_price;
    cout << prod_name << " price: " << price << endl;
    cout << "——————————" << endl;
    cout << endl;

    return true;
    }
    void Prod_Name(const char arr[])
    {
    ++Titles_Counter;

    if (Titles_Counter <= 0)
    return;

    if (Titles_Counter == 1)
    {
    Titles = new char* [Titles_Counter];
    Titles[0] = (char*)arr;
    }
    else
    {
    char** buffer_char = new char* [Titles_Counter];

    for (int i = 0; i < Titles_Counter; i )
    {
    if (i == (Titles_Counter – 1))
    buffer_char[i] = (char*)arr;
    else
    buffer_char[i] = Titles[i];
    }

    delete []Titles;
    Titles = nullptr;

    Titles = new char* [Titles_Counter];

    for (int i = 0; i < Titles_Counter; i )
    Titles[i] = buffer_char[i];

    delete[]buffer_char;
    buffer_char = nullptr;
    }
    }
    inline void Prod_List()
    {
    Prod_Name("Chokolate");
    Prod_Name("Milk");
    Prod_Name("Coffe");
    }
    int main()
    {
    float total_check{}, price{};

    Prod_List();

    while (Get_Price(price, Titles[Counter]))
    {
    total_check += price;
    ++Counter;
    }

    cout << "——————————" << endl;
    cout << "Total Check: " << total_check << endl;
    cout << "——————————" << endl;

    }

  7. #include
    using namespace std;

    #include

    int summ_products(int chocolate, int count_chocolate,
    int coffee, int count_coffee, int milk, int cnt_milk) {
    setlocale(LC_ALL, “RUS”);

    int summ_milk = milk * cnt_milk;
    int summ_coffee = coffee * count_coffee;
    int summ_choco = chocolate * count_chocolate;
    return summ_milk + summ_coffee + summ_choco;
    }
    int main()
    {
    int c;
    c = summ_products(5, 5, 5, 5, 5, 5);
    cout << c << endl;
    cout << summ_products(5, 5, 5, 5, 5, 6);

    }

Leave a Reply

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