Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Screenshot of output:

Coding:

// ElectricBillDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ElectricBill.h"
#include "ElectricBillDlg.h"
#include "afxdialogex.h"
#include<iostream>
#include <fstream>
#include <string>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

using namespace std;
// CElectricBillDlg dialog



CElectricBillDlg::CElectricBillDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CElectricBillDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CElectricBillDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CElectricBillDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_DOMESTIC, &CElectricBillDlg::OnBnClickedDomestic)
ON_BN_CLICKED(IDC_QUIT, &CElectricBillDlg::OnBnClickedQuit)
ON_BN_CLICKED(IDC_CALCULATE, &CElectricBillDlg::OnBnClickedCalculate)
END_MESSAGE_MAP()


// CElectricBillDlg message handlers

BOOL CElectricBillDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CElectricBillDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CElectricBillDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}



void CElectricBillDlg::OnBnClickedDomestic()
{
// TODO: Add your control notification handler code here
}


void CElectricBillDlg::OnBnClickedQuit()
{
// TODO: Add your control notification handler code here
exit(0);
}


void CElectricBillDlg::OnBnClickedCalculate()
{
// TODO: Add your control notification handler code here
CButton* domesticButton=(CButton*)GetDlgItem(IDC_DOMESTIC);
CButton* industrialButton=(CButton*)GetDlgItem(IDC_INDUSTRIAL);
CButton* comercialButton=(CButton*)GetDlgItem(IDC_COMERCIAL);

if (domesticButton ->GetCheck())
{
float result;
float kwh;
CString total;

kwh=GetDlgItemInt(IDC_CONSUMPTION);
result=kwh*0.3166;
total.Format (_T("%f"),result);
SetDlgItemText(IDC_RESULT, total);

ofstream ElectricBill;
ElectricBill.open("../TotalPayment.txt",ios::out | ios::trunc);

if (ElectricBill.is_open())
{
ElectricBill<<"Total Amount Needed To Be Pay : " <<result;
}
else
{
SetDlgItemText(IDC_NOTE, _T("Payment unable to record"));
}
}

else if (industrialButton ->GetCheck())
{
float result;
float kwh;
CString total;

kwh=GetDlgItemInt(IDC_CONSUMPTION);
result=kwh*0.3615;
total.Format(_T("%f"),result);
SetDlgItemText(IDC_RESULT, total);

ofstream ElectricBill;
ElectricBill.open("../TotalPayment.txt",ios::out | ios::trunc);

if (ElectricBill.is_open())
{
ElectricBill<<"Total Amount Needed To Be Pay : " <<result;
}
else
{
SetDlgItemText(IDC_NOTE, _T("Payment unable to record"));
}
}

else if (comercialButton -> GetCheck())
{
float result;
float kwh;
CString total;

kwh=GetDlgItemInt(IDC_CONSUMPTION);
result=kwh*0.4792;
total.Format(_T("%f"),result);
SetDlgItemText(IDC_RESULT, total);

ofstream ElectricBill;
ElectricBill.open("../TotalPayment.txt",ios::out | ios::trunc);

if (ElectricBill.is_open())
{
ElectricBill<<"Total Amount Needed To Be Pay : " <<result;
}
else
{
SetDlgItemText(IDC_NOTE, _T("Payment unable to record"));
}
}

else
{

SetDlgItemText(IDC_OUTPUT, _T("Please Insert A Number In Electric
Consumption And Choose One Option."));

}


}

You might also like