Question: Hello, I need help with my C++ program assignment, it's based on the book, C++ Programing 7th Edition . Assignment Convert a Struct to a
Hello, I need help with my C++ program assignment, it's based on the book, C++ Programing 7th Edition.
Assignment
| Convert a Struct to a Class Convert an existing program that uses a struct for data storage to use a class for data storage. | ||||||||||||||||||||||||||||||
| Purpose | Learn how to add a class to a program. Create an array of objects. Pass data to, and retrieve data from, an object. | |||||||||||||||||||||||||||||
| Instructions | Using Microsoft Visual Studio create a C++ program that solves the following problem.
|
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Below is the code for my Main program entry
-----------------------------------------------------------------------------
#include "stdafx.h" #include
using namespace std;
struct WaterBillType { string AccountNo; int AccountType; string BillMonth; float BillAmount; };
WaterBillType WaterBill[4];
void SetBillData(int item, string accNo, int accType, string Mo, float amt) { WaterBill[item].AccountNo = accNo; WaterBill[item].AccountType = accType; WaterBill[item].BillMonth = Mo; WaterBill[item].BillAmount = amt; }
string CreateDataLine(int item) { string ReturnString; char buf[9];
sprintf_s(buf, "%.2f", WaterBill[item].BillAmount);
ReturnString = "Account No. " + WaterBill[item].AccountNo + " " + "Account Type " + to_string(WaterBill[item].AccountType) + " (1 = Residential, 2 = Commercial, 3 = Industrial) " + "Billing Month " + WaterBill[item].BillMonth + " " + "Billing Amount $" + buf + " ";
return ReturnString; }
int _tmain(int argc, _TCHAR* argv[]) { SetBillData(0, "ZPK189834", 1, "May, 2017", 214.12); SetBillData(1, "COM882485", 2, "May, 2017", 798.19); SetBillData(2, "AIF157893", 3, "May, 2017", 12429.80); SetBillData(3, "AUV456719", 3, "May, 2017", 9781.48);
cout << "Outstanding Water Bills ";
for (int i = 0; i < 4; i++) cout << CreateDataLine(i) << endl;
cout << endl; system("pause"); return 0; }
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Below is my Class (ClassWaterBType.cpp)
-----------------------------------------------------------------------------
#include "stdafx.h" #include "ClassWaterBType.h"
ClassWaterBType::ClassWaterBType() { }
ClassWaterBType::~ClassWaterBType() { }
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Below is my Class header (ClassWaterBType.h)
-----------------------------------------------------------------------------
#pragma once
class ClassWaterBType { public: ClassWaterBType(); ~ClassWaterBType(); };
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
