Untitled

 avatar
unknown
plain_text
4 months ago
3.6 kB
13
Indexable
#include <iostream>
using namespace std;

int main() {
    cout << "=== Camera Storage Calculator ===\n";
    cout << "(Using: Geometry, Sets, Counting)\n\n";

    // ----------------------------------------------------
    // 1. เรขาคณิต (Geometry) - กำหนดขนาดภาพ
    // ----------------------------------------------------
    // สมมติกล้องความละเอียด 24 ล้านพิกเซล (6000 x 4000)
    double width = 6000;
    double height = 4000;
    
    // พื้นที่ (Area) = กว้าง x สูง
    double pixels = width * height; 
    
    // แปลงเป็นขนาดไฟล์คร่าวๆ (สมมติ 1 ล้านพิกเซล กินที่ 0.3 MB)
    double Imagesize = (pixels / 1000000.0) * 0.3;

    cout << "[Geometry]\n";
    cout << "- Resolution: " << width << "x" << height << " pixels\n";
    cout << "- File size per photo: approx " << Imagesize << " MB\n\n";

    // ----------------------------------------------------
    // 2. เซต (Sets) - กรอกข้อมูลเพื่อคัดแยก
    // ----------------------------------------------------
    int totalShots, badShots;

    cout << "[Sets]\n";
    cout << "1. How many photos did you take? : ";
    cin >> totalShots;  // กรอกจำนวนรูปทั้งหมด

    cout << "2. How many are blurry/bad photos? : ";
    cin >> badShots;    // กรอกจำนวนรูปเสีย

    // Operation: Set Difference (ผลต่างเซต)
    // รูปที่เก็บจริง = รูปทั้งหมด - รูปเสีย
    int keepShots = totalShots - badShots;

    // กันเหนียว: ถ้ารูปเสียมากกว่ารูปที่ถ่ายมา (User กรอกผิด)
    if (keepShots < 0) {
        cout << "\nERROR: You cannot delete more photos than you took!\n";
        return 1;
    }

    cout << ">> Photos to Keep: " << keepShots << " photos\n\n";

    // ----------------------------------------------------
    // 3. การนับ (Counting) - คำนวณพื้นที่จัดเก็บ
    // ----------------------------------------------------
    cout << "[Counting]\n";
    double cardCapacityGB;
    cout << "3. Enter your SD Card size (GB) (16, 32, 64 , 128 , 256 , 1024) : ";
    cin >> cardCapacityGB; // กรอกความจุการ์ด

    // แปลง GB เป็น MB (1 GB = 1024 MB)
    double totalSpaceMB = cardCapacityGB * 1024;

    // พื้นที่ที่ถูกใช้ไป (Used Space)
    double usedSpaceMB = keepShots * Imagesize;

    // พื้นที่คงเหลือ (Remaining Space)
    double freeSpaceMB = totalSpaceMB - usedSpaceMB;

    if (freeSpaceMB <= 0) {
        cout << "\n>> Warning: Your card is FULL! (Over capacity)\n";
    } else {
        // คำนวณว่าถ่ายเพิ่มได้อีกกี่รูป (Space / Size)
        int photosLeft = freeSpaceMB / Imagesize;

        cout << "\n-----------------------------------\n";
        cout << "Used Space: " << usedSpaceMB << " MB\n";
        cout << "Free Space: " << freeSpaceMB << " MB\n";
        cout << ">> You can take " << photosLeft << " more photos\n";
        cout << "-----------------------------------\n";
    }

    return 0;
}
Editor is loading...
Leave a Comment