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.

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

  1. Thank you for the opportunity to practice.
    It really helps in the realization of the material!

      1. In the second assignment error, The second variable is not equal to the first increase in three, and it is issued on the same with the following expression…

  2. ahahahah :D
    I am currently in a second complicated zadachu.I wrote instead 15 lines – 30 :D
    little protupila,but overall I left everything well.

  3. everything is good but not enough, I want more tasks and with the ever-increasing level of complexity! :)

  4. I enrolled in the second problem a little differently, regarding display, and in general all the same
    #include

    using namespace std;

    int main (int x, int y, int z)

    {
    x = 15;
    y = x * 3;
    z = x + y;

    cout << x << "\n" << y << "\n"<< z << "\n";

    system("pause");
    return 0;
    }

  5. and the third reason I also thought, you must itself determine the number of devices, and this turned out at me like this
    #include
    #include

    using namespace std;
    int total;

    void totalfunc();
    int main ()

    {
    setlocale(LC_CTYPE, "rus");
    totalfunc();
    system("pause");
    return 0;
    }

    void totalfunc()
    {
    int cups, spoon, saucer;

    cout < < cups; cout << spoon; cout << saucer; total = cups + spoon + saucer; cout << "Сумма предметов на столе равна: "; cout << total; }

  6. The decision on the first task. What are the good and bad side is, in my decision. newcomer,severely beat. (Rows not Russian because he wrote in Dev`e,not at home).

    #include
    #include

    using std::cout;
    using std::cin;
    using std::endl;

    int choko=0;
    int coffee=0;
    int milk=0;
    int tov=0;
    float sumch=0;
    float sumcof=0;
    float summilk=0;
    float sttov=0;

    int tovari();
    float stoimost();
    float summa();

    int main()
    {
    tovari();
    stoimost();
    summa();

    system("PAUSE");
    return 0;
    }

    int tovari()
    {
    cout<<"--------------------------------------------"<<"\n";

    cout<<"Vvedite kol-vo kuplennix productov \n";
    cout<<"--------------------------------------------"<<"\n";

    cout<<choko;
    cout<<coffee;
    cout<<milk;

    tov=choko+coffee+milk;

    cout<<"--------------------------------------------"<<"\n";
    cout<<"Obshee kol-vo kuplennix tovarov= "<<tov<<"\n";
    cout<<"--------------------------------------------"<<"\n";

    return 0;
    }

    float stoimost()
    {
    cout<<"--------------------------------------------"<<"\n";

    cout<<"Vvedite stoimost kuplennix productov \n";
    cout<<"--------------------------------------------"<<"\n";

    cout<<sumch;
    cout<<sumcof;
    cout<<summilk;

    return 0;
    }

    float summa()
    {
    cout<<"--------------------------------------------"<<"\n";
    cout<<"Stoimost pokupok \n";
    cout<<"--------------------------------------------"<<"\n";

    cout<<"--------------------------------------------"<<"\n";
    sumch*=choko;
    cout<<"Stoimost plitok shokolada= "<<sumch<<"\n";
    sumcof*=coffee;
    cout<<"Stoimost banok cofe= "<<sumcof<<"\n";
    summilk*=milk;
    cout<<"Stoimost paketov moloka= "<<summilk<<"\n";
    cout<<"--------------------------------------------"<<"\n";
    sttov=sumch+sumcof+summilk;
    cout<<"Obshya summa k oplate= "<<sttov<<"\n";
    cout<<"--------------------------------------------"<<"\n";

    return 0;
    }

    1. As the dofiga code and really useless.

      using namespace std;

      int main() {

      int milk, chocolate, coffe;
      float milkcost = 10.1;
      float chocolatecost = 11.85;
      float coffecost = 15.4;
      cout << milk;
      cout << chocolate;
      cout << coffe;
      cout << "You buy " << milk << " botles of milk " << milkcost << " * " << milk << " = " << (milk * milkcost) << endl;
      cout << "You buy " << chocolate << " chocolates " << chocolatecost << " * " << chocolate << (chocolate * chocolatecost) << endl;
      cout << "You buy " << coffe << " coffe's " << coffecost << " * " << coffe << (coffe * coffecost) << endl;
      cout << "Total: " << (milk * milkcost) + (chocolate * chocolatecost) + (coffe * coffecost)
      return 0;
      system ("pause");
      };

  7. Formulation of the task:
    Write program calculating circuit resistance elektriche¬skoy, consisting of two parallel-connected resistors. The recommended screen view during execution of the program (data, user Submitted, bolded).
    Calculation of the electrical circuit in parallel connection of resistance elements.
    Enter the raw data:
    The magnitude of the first resistance (ohm) -> 15
    The magnitude of the second resistance (ohm)-> 20
    circuit resistance: 8.57 ohm
    Developing solutions algorithm.

    chart

    Defining the program

    L - value of the first resistance (ohm), a float variable
    G - a second resistance value (ohm), a float variable
    R - resistance of the circuit (ohm), a float variable

    The full text of the program
    //---------------------------------------------------------------------------

    #include
    #include
    void main ()

    {
    float L, G, R;
    printf("velichina pervogo soprotivlenia (Om) : ") ;
    scanf("%f", &L) ;
    printf("velichina vtorogo soprotivlenia (Om) : ") ;
    scanf("%f", &G) ;
    R=L*G/(L+G);
    printf("\n soprotivlenie cepi %f Om",R);
    scanf("%f", &L);
    }
    //---------------------------------------------------------------------------

    The results of the work program
    When the program on the screen, such results have been removed:

    The magnitude of the first resistance: 15
    The magnitude of the second resistance 20
    circuit resistance 8,57

  8. The first line of the input file are two integers a and b (-109 ≤ a, b ≤ 109). Your program needs to display a single number - the result of the expression a – b.

    Input data:
    Two integers a and b (-109 ≤ a,b ≤ 109).

    Output:
    the result of the expression a – b.

Leave a Reply

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