Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class ConvertByte
- {
- public:
- //Defining the default constructor
- ConvertByte();
- //Prompts the user to enter a value in MB.
- void read();
- //Mutator which converts the value entered from MB
- //into bytes.
- void convert_to_byte();
- //Accessor which outputs the value that is stored
- //in byte_result.
- void print();
- //Destructor used to remove an object that was
- //created.
- ~ConvertByte();
- private:
- unsigned long int mb_private;
- unsigned long int byte_result;
- unsigned long int MB_in_bytes;
- };
- //Default constructor which also sets the default
- //value for MB_in_bytes (now many bytes make up
- // a megabyte.
- ConvertByte::ConvertByte()
- {
- MB_in_bytes = 1048576;
- }
- //Prompts the user for the MB to convert and
- //stores the input in the private interface
- //variable mb_private.
- void ConvertByte::read()
- {
- cout << "What number, in megabytes, would you like to convert to bytes? ";
- cin >> mb_private;
- }
- //Mutator which takes the value stored in mb_private
- //and converts into bytes and stores that result in
- //the private interface variable byte_result.
- void ConvertByte::convert_to_byte()
- {
- byte_result = mb_private * MB_in_bytes;
- }
- //Sends the result of converting the megabyte number entered
- //to stout.
- void ConvertByte::print()
- {
- cout << mb_private << " MB is equal to " << byte_result << " bytes.";
- }
- //Destrutor used to remove the object.
- ConvertByte::~ConvertByte(){}
- int main ()
- {
- //Create byteObject
- ConvertByte byteObject;
- /*
- Read in the number of megabytes to convert
- then convert it to bytes and then print
- the result to screen.
- */
- byteObject.read();
- byteObject.convert_to_byte();
- byteObject.print();
- //Use a destructor to destroy the object.
- byteObject.~ConvertByte();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment