#include #include #include using namespace std; int main(){ //Variables int cylinders, sectors, heads; unsigned int capacity; const int bytes_in_sector = 512; int dcapacity, bcapacity; //Constants const int KB = static_cast(pow(10.0,3)); const int MB = static_cast(pow(10.0,6)); const int GB = static_cast(pow(10.0,9)); const int KiB = static_cast(pow(2.0,10)); const int MiB = static_cast(pow(2.0,20)); const int GiB = static_cast(pow(2.0,30)); cout << "This program takes the number of cylinders, sectors, and" << endl; cout << "heads on a hard drive and returns the capacity of " << endl; cout << "the drive." << endl << endl; cout << "Enter the number of cylinders: "; cin >> cylinders; cout << "Enter the number of sectors: "; cin >> sectors; cout << "Enter the number of heads: "; cin >> heads; if(cylinders <= 0 || sectors <= 0 || heads <= 0){ cout << "Your computer has no capacity!" << endl; cout << "Goodbye." << endl; exit (1); } capacity = cylinders * sectors * heads * bytes_in_sector; cout << "Capacity in bytes: " << capacity << endl; cout << "The capacity of the disk is: " << endl; // Do this in decimal cout << "Decimal bytes: "; dcapacity = capacity; cout << (dcapacity - dcapacity%GB)/GB << " GB "; dcapacity = dcapacity%GB; cout << (dcapacity - dcapacity%MB)/MB << " MB "; dcapacity = dcapacity%MB; cout << (dcapacity - dcapacity%KB)/KB << " KB and "; dcapacity = dcapacity%KB; cout << dcapacity << " B. " << endl; // Do this in binary cout << "Binary bytes: "; bcapacity = capacity; cout << (bcapacity - bcapacity%GiB)/GiB << " GiB "; bcapacity = bcapacity%GiB; cout << (bcapacity - bcapacity%MiB)/MiB << " MiB "; bcapacity = bcapacity%MiB; cout << (bcapacity - bcapacity%KiB)/KiB << " KiB and "; bcapacity = bcapacity%KiB; cout << bcapacity << " B. " << endl; return 0; }