|
help with classes
I'm making a simple gui, that loads in to matrices from files located on "a:" and I'm making my own simple matrix class and matrix math class, everything looks correct to me and even thou I include the header file for the math and matrix class to the gui class it always says these errors: it was created using MFC and the MFC Application wizard with Use MFC in a Shared DLL.
Thanks for any help!
error C2061: syntax error : identifier 'ropaMatrix'
syntax error : missing ';' before identifier 'matrixA'
error C2501: 'CpayneMatDlg::ropaMatrix' : missing storage-class or type specifiers
error C2501: 'CpayneMatDlg::matrixA' : missing storage-class or type specifiers
code:
// payneMatDlg.cpp : implementation file
#include <iostream>
#include <string>
#include <fstream.h>
#include "calculate.h"
#include "stdafx.h"
#include "payneMat.h"
#include "payneMatDlg.h"
#include ".\paynematdlg.h"
#include "rpayneMatrix.h"
#include <string>
#include <sstream>
#include <fstream>
#include <stdlib.h>
using namespace std;
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CpayneMatDlg dialog
CpayneMatDlg::CpayneMatDlg(CWnd* pParent /*=NULL*/)
: CDialog(CpayneMatDlg::IDD, pParent)
, operations(0)
, m(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CpayneMatDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m);
DDV_MinMaxInt(pDX, m, 0, 10);
//{{AFX_DATA_MAP(CGuiDlg)
DDX_Radio(pDX, IDC_RADIO1, operations);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CpayneMatDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
ON_BN_CLICKED(IDC_RADIO1, OnBnClickedRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnBnClickedRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnBnClickedRadio3)
ON_BN_CLICKED(IDC_RADIO4, OnBnClickedRadio4)
ON_BN_CLICKED(IDC_RADIO5, OnBnClickedRadio5)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
END_MESSAGE_MAP()
// CpayneMatDlg message handlers
BOOL CpayneMatDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
}
void CpayneMatDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CpayneMatDlg::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
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CpayneMatDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CpayneMatDlg::OnEnChangeEdit1()
{
}
void CpayneMatDlg::OnBnClickedRadio1()
{
if (UpdateData(TRUE))
{
calc.add(matrixA,matrixB);
UpdateData(FALSE);
Invalidate();
}
}
void CpayneMatDlg::OnBnClickedRadio2()
{
if (UpdateData(TRUE))
{
calc.subtract(matrixA,matrixB);
UpdateData(FALSE);
Invalidate();
}
}
void CpayneMatDlg::OnBnClickedRadio3()
{
if (UpdateData(TRUE))
{
calc.multiply(matrixA,matrixB);
UpdateData(FALSE);
Invalidate();
}
}
void CpayneMatDlg::OnBnClickedRadio4()
{
if (UpdateData(TRUE))
{
calc.transpose(matrixA);
UpdateData(FALSE);
Invalidate();
}
}
void CpayneMatDlg::OnBnClickedRadio5()
{
if (UpdateData(TRUE))
{
calc.transposeB(matrixB);
UpdateData(FALSE);
Invalidate();
}
}
void CpayneMatDlg::OnBnClickedButton1()
{
//Loading the matrix 1 from a file
if (UpdateData(TRUE))
{
matrixA.loadMatrix(m);
UpdateData(FALSE);
Invalidate();
}
}
void CpayneMatDlg::OnBnClickedButton2()
{
//Loading the matrix 2 from a file
if (UpdateData(TRUE))
{
matrixB.loadMatrixB(m);
UpdateData(FALSE);
Invalidate();
}
}
// payneMatDlg.h : header file
//
#pragma once
#include "ropaMatrix.h"
#include <iostream>
#include <string>
#include "matrixMath.h"
#include "stdafx.h"
#include "payneMat.h"
//#include "payneMatDlg.h"
#include ".\paynematdlg.h"
#include <string>
#include <sstream>
#include <fstream>
#include <stdlib.h>
using namespace std;
// CpayneMatDlg dialog
class CpayneMatDlg : public CDialog
{
// Construction
public:
CpayneMatDlg(CWnd* pParent = NULL); // standard constructor
int operations;
int m;
ropaMatrix matrixA;
ropaMatrix matrixB;
matrixMath calc;
// Dialog Data
enum { IDD = IDD_PAYNEMAT_DIALOG };
// Implementation
protected:
virtual void DoDataExchange(CDataExchange* pDX);
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnEnChangeEdit1();
afx_msg void OnBnClickedRadio1();
afx_msg void OnBnClickedRadio2();
afx_msg void OnBnClickedRadio3();
afx_msg void OnBnClickedRadio4();
afx_msg void OnBnClickedRadio5();
afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedButton2();
DECLARE_MESSAGE_MAP()
};
#pragma once
#include <fstream>
#include <sstream>
#include <fstream>
#include <stdlib.h>
#include <iostream>
#include ".\ropaMatrix.h"
using namespace std;
class matrixMath
{
public:
matrixMath(void);
~matrixMath(void);
ofstream matfile;
int rslt[10][10];
void add(ropaMatrix matA, ropaMatrix matB);
void subtract(ropaMatrix matA, ropaMatrix matB);
void multiply(ropaMatrix matA, ropaMatrix matB);
void transposeA(ropaMatrix matA);
void transposeB(ropaMatrix matB);
};
#include "StdAfx.h"
#include ".\matrixmath.h"
#include "ropaMatrix.h"
matrixMath::matrixMath(void)
{
}
matrixMath::~matrixMath(void)
{
}
void matrixMath::add(ropaMatrix matA, ropaMatrix matB)
{
//UpdateData();
for(int row =0; row < matB.getSize(); row++)
for(int col =0;col < matB.getSize(); col++)
rslt[row][col]= matA.getValue(row,col) + matB.getValue(row,col);
matfile.open("a:\\addm.txt", ios::out);
for(int row = 0; row < matB.getSize(); row++){
for(int col = 0; col < matB.getSize(); col++)
matfile << rslt[row][col] <<" ";
matfile <<endl;
}
matfile.close();
// UpdateData(FALSE);
}
void matrixMath::subtract(ropaMatrix matA, ropaMatrix matB)
{
// UpdateData();
for(int row = 0; row < matB.getSize(); row++)
for(int col =0;col < matB.getSize(); col++)
rslt[row][col] = matA.getValue(row,col) - matB.getValue(row,col);
matfile.open("a:\\subm.txt", ios::out);
for(int row = 0; row < matB.getSize(); row++){
for(int col = 0; col < matB.getSize(); col++)
matfile << rslt[row][col]<<" ";
matfile <<endl;
}
matfile.close();
// UpdateData(FALSE);
}
void matrixMath::multiply(ropaMatrix matA, ropaMatrix matB)
{
//UpdateData();
for(int row = 0; row < matB.getSize(); row++){
for(int col = 0 ;col < matB.getSize(); col++){
rslt[row][col] =0 ;
for(int n = 0; n < matB.getSize(); n++)
rslt[row][col]+= matA.getValue(n,row) * matB.getValue(col,n);
}
}
matfile.open("a:\\multm.txt", ios::out);
for(int row = 0; row < matB.getSize(); row++){
for(int col = 0; col < matB.getSize(); col++)
matfile << rslt[row][col] <<" ";
matfile <<endl;
}
matfile.close();
// UpdateData(FALSE);
}
void matrixMath::transposeA(ropaMatrix matA)
{
// UpdateData();
for( int row = 0; row < matA.getSize(); row++)
for(int col =0; col < matA.size; col++)
rslt[row][col]= matA.getValue(col,row);
matfile.open("a:\\transa.txt", ios::out);
for(int row = 0; row < matA.getSize(); row++){
for(int col = 0; col < matA.getSize(); col++)
matfile << rslt[row][col] <<" ";
matfile <<endl;
}
matfile.close();
// UpdateData(FALSE);
}
void matrixMath::transposeB(ropaMatrix matB)
{
//UpdateData();
for(int row =0;row < matB.getSize(); row++)
for(int col =0;col < matB.getSize(); col++)
rslt[row][col]= matB.getValue(row,col);
matfile.open("a:\\transb.txt", ios::out);
for(int row = 0; row < matB.getSize(); row++){
for(int col = 0; col < matB.getSize(); col++)
matfile << rslt[row][col] <<" ";
matfile <<endl;
}
matfile.close();
// UpdateData(FALSE);
}
#pragma once
#include "payneMatDlg.h"
class ropaMatrix
{
public:
ropaMatrix(void);
~ropaMatrix(void);
int size;
int matrixPayne[10][10];
int getValue(int Rindex, int Cindex);
int getSize(void);
void loadA(int matSize);
void loadB(int matSize);
void zeros(void);
};
#include "StdAfx.h"
#include ".\ropamatrix.h"
ropaMatrix::ropaMatrix(void)
{
}
ropaMatrix::~ropaMatrix(void)
{
}
int ropaMatrix::getValue(int Rindex, int Cindex)
{
return matrixPayne[Rindex][Cindex];
}
int ropaMatrix::getSize(void)
{
return size;
}
void ropaMatrix::loadA(int matSize)
{
size = matSize;
zeros();
ifstream matfile;
matfile.open("a:\\test1.txt", ios::in);
for(int row = 0; row < size; row++)
for(int col = 0; col < size; col++)
matfile >> matrixPayne[row][col];
matfile.close();
}
void ropaMatrix::loadB(int matSize)
{
size = matSize;
zeros();
ifstream matfile;
matfile.open("a:\\test2.txt", ios::in);
for(int row = 0; row < size; row++)
for(int col = 0; col < size; col++)
matfile >> matrixPayne[row][col];
matfile.close();
}
void ropaMatrix::zeros(void)
{
for(int i =0; i < size; i++)
for(int j = 0; j < size; j++)
matrixPayne[i][j] = 0;
}
|