This is the question. Q: You must create a ZipCode class, the declaration of whi
ID: 3763961 • Letter: T
Question
This is the question.
Q: You must create a ZipCode class, the declaration of which is attached, and a ZipDigit class. The ZipDigit class should be constructed with either no arguments (default to 0), an integer (for storage), or a binary bitstring of 5 bits (for conversion to decimal and storage). The ZipDigit class should expose a method, getDigit(), which takes no arguments and returns the stored decimal value of the digit. The ZipCode class should store 5 ZipDigit instances in an array.
And he gave the code.
zip.hpp
#ifndef ZIPCODE_HPP
#define ZIPCODE_HPP
#include <iostream>
using namespace std;
class ZipCode
{
public:
ZipCode(int zip);
// Constructs a ZipCode from an integer zip code value
ZipCode(string code);
// Constructs a ZipCode from a string of 1's and 0's
string get_bar_code();
// Returns the zip code in bar form
int get_zip_code();
// Returns the zip code in numeric form
private:
int zip;
int parse_bar_code(string code);
// Returns an integer, parsed from the given bar code.
// If the code is not valid, this function will print
// an error message and then exit.
};
#endif
Please, answer me.
Explanation / Answer
Header file:
//zip.hpp
#ifndef ZIPCODE_HPP
#define ZIPCODE_HPP
#include <iostream>
using namespace std;
class ZipDigit
{
private: int x;
public:
ZipDigit()
{
this->x=0;
}
void setDigit(int x)
{
this->x=x;
}
int getDigit()
{
return x;
}
};
class ZipCode
{
public:
ZipCode(int zip);
ZipCode(string code);
string get_bar_code();
int get_zip_code()
{
return zip;
}
private:
int zip;
int parse_bar_code(string code);
ZipDigit ZD[5]; zip digit instances
};
#endif
program:
#include "stdafx.h"
#include"zipcode.h"
#include<iostream>
using namespace std;
int main()
{
ZipCode z(4);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.