1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
// myform.h : declaration of classes
#ifndef MYFORM_H
#define MYFORM_H
#define NUMFLDS 4
#define MAXFLDLEN 25
class Form; // forward declaration
class Field {
private:
char *fldPrompt;
unsigned short fldLen; // actual length without '\0' for char fields
unsigned short startRow;
unsigned short startCol;
public:
Field(char *pmpt, unsigned short len, unsigned short row, unsigned short col);
friend class Form; // allow Form to access Field's private members
~Field();
};
class Form {
private:
Field *fields[NUMFLDS];
void *data[NUMFLDS];
unsigned short fldNums;
public:
Form(Field *flds, unsigned short numFlds, void *dta);
~Form();
void show(void);
void process(void);
};
#endif
===
// myform.cpp
#include <stdio.h>
//#include <conio.h>
#include <string.h>
#include "myform.h"
// Field implementation
Field::Field(char *pmpt, unsigned short len, unsigned short row, unsigned short col)
{
fldPrompt = pmpt;
fldLen = len;
startRow = row;
startCol = col;
}
Form::Form(Field *flds, unsigned short numFlds, void *dta)
{
fldNums = numFlds;
for (int i = 0; i < fldNums; i++) {
fields[i] = flds[i]; <<<<< ERROR 1
}
show();
process();
}
void Form::show(void)
{
for (int i = 0; i < fldNums; i++) { // show the form
// gotoxy(fields[i].startCol,fields[i].startRow);
printf(fields[i].fldPrompt); <<<< ERROR 2
// gotoxy(fields[i].startCol,
fields[i].startRow+strlen(fields[i].fldPrompt)); <<<< ERROR 2
}
}
void Form::process(void)
{
// commented out
}
===
// myfrmtst.cpp
#include <stdio.h>
//#include <conio.h>
#include "myform.h"
const int numfields = 4;
/******************************* data ********************************/
char firstName[13]; /* allow for terminating '\0' in input bufs */
char surName[26];
char gender[2];
char age[3];
int main(void)
{
Field *fld[] = {
&Field("First Name : ", 12, 4, 17),
&Field("Surname : ", 25, 6, 17),
&Field("Gender : ", 1, 8, 17),
&Field("Age : ", 2, 10,17)
};
void *dat[] = { &firstName, &surName, &gender, &age };
Form frm(*fld, numfields, *dat);
// getch();
return 0;
}
|