কম্পিউটার টিউটোরিয়াল

C++ প্রোগ্রাম: ট্যাঙ্ক ওভারফ্লো, আন্ডারফ্লো অথবা ভরা যাবে কিনা যাচাই করা

ট্যাঙ্ক পূরণের হার, ট্যাঙ্কের উচ্চতা এবং ব্যাসার্ধ দেওয়া থাকলে, নির্দিষ্ট সময়ে ট্যাঙ্ক ওভারফ্লো, আন্ডারফ্লো নাকি ঠিকমতো ভরা যাবে কিনা তা যাচাই করতে হবে।

উদাহরণ

Input: radius = 2, height = 5, rate = 10 Output: tank overflow
Input: radius = 5, height = 10, rate = 10 Output: tank underflow

ব্যবহৃত পদ্ধতি:

  • পূরণের হার, উচ্চতা এবং ব্যাসার্ধ ইনপুট নিন
  • ট্যাঙ্কের ভলিউম বের করে পানির প্রকৃত প্রবাহের হার নির্ণয় করুন
  • শর্তগুলো চেক করে ফলাফল নির্ধারণ করুন
    • যদি expected < original হয় তবে ট্যাঙ্ক ওভারফ্লো হবে
    • যদি expected > original হয় তবে ট্যাঙ্ক আন্ডারফ্লো হবে
    • যদি expected = original হয় তবে ট্যাঙ্ক ঠিক সময়ে ভরা যাবে
  • ফলাফল প্রিন্ট করুন

আলগরিদম

Start
Step 1 -> declare function to calculate volume of tank
    float volume(int rad, int height)
    return ((22 / 7) * rad * 2 * height)
step 2 -> declare function to check for overflow, underflow and filled
    void check(float expected, float orignal)
        IF (expected < orignal)
            Print "tank overflow"
        End
        Else IF (expected > orignal)
            Print "tank underflow"
        End
        Else
            print "tank filled"
        End
Step 3 -> Int main()
    Set int rad = 2, height = 5, rate = 10
    Set float orignal = 70.0
    Set float expected = volume(rad, height) / rate
    Call check(expected, orignal)
Stop

C++ প্রোগ্রাম উদাহরণ

#include <bits/stdc++.h>
using namespace std;

//calculate volume of tank
float volume(int rad, int height) {
    return ((22 / 7) * rad * 2 * height);
}

//function to check for overflow, underflow and filled
void check(float expected, float orignal) {
    if (expected < orignal)
        cout << "tank overflow";
    else if (expected > orignal)
        cout << "tank underflow";
    else
        cout << "tank filled";
}

int main() {
    int rad = 2, height = 5, rate = 10;
    float orignal = 70.0;
    float expected = volume(rad, height) / rate;
    check(expected, orignal);
    return 0;
}

আউটপুট

tank overflow
  1. সি++-এ অ্যারে বিটোনিক (Bitonic) কিনা তা যাচাই করার প্রোগ্রাম

  2. C++-এ DFS ব্যবহার করে গ্রাফ বাইপার্টাইট (Bipartite) কিনা তা যাচাই করুন

  3. C++-এ ইনভোলিউটরি ম্যাট্রিক্স যাচাই করার প্রোগ্রাম

  4. C++ প্রোগ্রাম: লিপ ইয়ার (Leap Year) যাচাই