The basics of programming in c++ for beginners

Tasks: arithmetic operations in C ++

If you have already read the articleArithmetic operations in C ++ you can begin to practice.

1. Common task:  Given the four-digit number (for example 5678), display the numbers in reverse order of which is the number of member. That is, we should see on the screen 8765. Tip: to take from among the individual numbers, should be applied to the modulo 10.

2. The site of almost any commercial bank, you can find the so-called Deposit calculator, which allows people to, not wishing to go into the formula for calculating interest rates, to know how much they will receive. To do this, they just fill in certain fields, press the button and see the result. This is a simple program, which has already been able to write each one of you. So, a task: The user enters the amount of the deposit and the number of months of keeping money in the bank. It is necessary to calculate and show the screen profit from the deposit in a month,  for the entire term of the deposit, and the total amount payable at the end of the period.  Currency let it be – U.S. dollar. Interest rate – 5% APR.  The formula for calculating percent per month–                      SumDeposit * (interest rate / 100)  / daysperyear * dayspermonths.

Perhaps you have any questions about the solution of tasks – ask them in the comments!

115 thoughts on “Tasks: arithmetic operations in C ++

  1. Мне кажется так точнее:
    #include
    using namespace std;

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

    float a, b;
    float mes1 = 0;
    float god1 = 0;
    float sum = 0;
    cout <> a;
    cout <> b;
    cout << "Проценты в месяц: ";
    mes1 = a*5/100/12;
    cout << mes1 << endl;
    cout << "Проценты в год: ";
    god1 = mes1 * 12;
    cout << god1 << endl;
    cout << "Общая сумма процентов: ";
    mes1 = mes1 * 12 * b;
    cout << mes1 << endl;
    cout << "Общая сумма выплаты: ";
    sum = a + b * god1;
    cout << sum << endl;

    cout << endl;
    return 0;
    }

  2. #include
    using namespace std;

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

    float a = 0;
    // ” ‘ a ‘ – сумма депозита
    float b = 0;
    // ” ‘ b ‘ – кол-во месяцев хранения денег в банке
    float c = 0.05;
    // ” ‘ c ‘ – interest rate 5 %”
    float d = 365;
    // ” ‘ d ‘ – кол-во дней в году установлено как постоянное число
    float e = 31;
    // ” ‘ e ‘ – кол-во дней в месяце установлено как постоянное число

    cout << "Deposit amount" <> a;

    cout << "Months" <> b;

    cout << "Profit per month" << " " << a * c / d * e << endl;

    cout << "All term profit" << " " << a *c / d * e * b << endl;

    cout << "Total amount payable after term" << " " << a + (a *c / d * e *b) << endl;

    return 0;
    }

  3. int main(){
    setlocale(LC_ALL, “RUS”);

    int k;
    cout <> k;

    while (k%10!=0){
    cout << k % 10;
    k = k / 10;
    }
    cout << endl;

    system("pause");

    return 0;
    }

  4. Маленько не по заданию, но считала так:

    int main(){
    setlocale(LC_ALL, “RUS”);
    float sum, profit, annual = 0.05;
    int monthInYear = 12, amountMonth;
    cout <> sum;
    cout <> amountMonth;
    cout << endl << "Сумма: " << sum + (amountMonth*(sum*annual)/monthInYear) << " rub" << endl;
    system("pause");
    return 0;
    }

  5. #include ;
    #include ;
    #include ;
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int sum_of_dep = 0;
    int deposit_term = 0;
    short day_start = 0;
    short month_start = 0;
    int year_start = 0;
    short day_end = 0;
    short month_end = 0;
    int year_end = 0;
    int sum_of_procent = 0;
    int day_in_month = 30;
    float deposit_rate = 5;
    int year_duration = 360;

    cout << "Введите сумму депозита: " <> sum_of_dep;

    cout << "Укажите дату оформления депозита(день/месяц/год): " << endl;
    cout << "День: " <> day_start;
    cout << "Месяц: " <> month_start;
    cout << "Год: " <> year_start;

    if (year_start>9999 || year_start12 || month_start31 || day_start 28)
    cout << "Некоректная дата" << endl;

    cout << endl;

    cout << "Укажите дату окончания депозита(день/месяц/год): " << endl;
    cout << "День: " <> day_end;
    cout << "Месяц: " <> month_end;
    cout << "Год: " <> year_end;

    if (year_end>9999 || year_end12 || month_end31 || day_end 28)
    cout << "Некоректная дата" << endl;

    cout << endl;
    // расчет разницы между днями с помощью вычисления юлианского дня
    float a1, m1, a2, m2;
    int a4 = 12; // переменная в формуле для расчета юлианского дня
    int y1, y2, jdn1, jdn2;

    a1 = (14 – month_start) / a4;
    y1 = year_start + 4800 – A1;
    m1 = (month_start + (12 * A1)) – 3;

    jdn1 = day_start + ((153 * m1 + 2) / 5) + 365 * y1 + (y1 / 4) – (y1 / 100) + (y1 / 400) – 32045;

    a2 = (14 – month_end)/a4;
    y2 = year_end + 4800 – a2;
    m2 = (month_end + (12 * a2)) – 3;
    jdn2 = day_end + ((153 * m2 + 2) / 5) + 365 * y2 + (y2 / 4) – (y2 / 100) + (y2 / 400) – 32045;

    deposit_term = jdn2jdn1;
    cout << "Срок депозита = " << deposit_term << endl;

    //расчет начисления процентов по дням. Годовая ставка 5%.
    //расчет процентной ставки за день:

    float procent_on_day;
    procent_on_day = (deposit_rate / year_duration) * 10;
    double a = procent_on_day; //округление до сотых
    double b = a*1000.0;
    int tmp = b + 0.5;
    b = (double)tmp / 1000.0;
    procent_on_day = b;
    cout << "Процентная ставка – 5% APR" << endl;

    //проценты за месяц (базовое усредненное кол-во дней в месяце равно 30)
    float procent_on_month;
    procent_on_month = procent_on_day * 30;
    //Прибыль по депозиту за месяц
    float profit_on_month;
    profit_on_month = (procent_on_month * sum_of_dep) / 100;
    //Прибыль по депозиту за весь срок
    float profit_on_all_term;
    profit_on_all_term = (procent_on_day * deposit_term) * sum_of_dep / 100;
    double x = profit_on_all_term; //округление до сотых
    double y = x*100.0;
    int tmp2 = y + 0.5;
    y = (double)tmp2 / 100.0;
    profit_on_all_term = y;

    cout << "Процентов начислено за месяц: " << procent_on_month << endl;
    cout << "Прибыль по депозиту за месяц: " << profit_on_month << endl;
    cout << "Прибыль по депозиту за весь срок:" << profit_on_all_term << endl;

    system("pause");
    return 0;
    }

  6. #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “RUS”);
    int sum = 0;
    int srok = 0;
    float sum1 = 0;
    cout <> sum;
    cout <> srok;
    sum1 = sum + sum * srok * 5 / 36500;
    cout << "\n\n Поздравляем! Сумма вашего вклада с процентами через " << srok << " месяцев составит: " << sum1 << " Баксов :-)\n\n\n Наш банк желает Вам удачи и хорошего настроения!!!\n\n\n\n\n\n\n\n\n";
    setlocale (LC_ALL, "RUS");
    // std::cout << "Hello World!\n";
    return 0;
    }

Leave a Reply

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