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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#include <iostream>
#include <cstring>
#include <cctype>
#include "graph1.h"
using namespace std;
//Prototypes are below:
bool validateName(char* name);
char* getString(char* prompt);
bool validateAddress(char* address);
bool validatePhone(char* phone);
char* convertToUpper(char* string);
void displayFields(char* name, char* address, char* phone);
int main()
{
//Variable Declaration/Initialization
char* name = NULL;
char* address = NULL;
char* phone = NULL;
char* upperName = NULL;
bool res = false;
//Display graphics window
displayGraphics();
//Get the fields - validate based on function
do
{
//Get the name
name = getString("Enter Name: ");
//validate the name
res = validateName(name);
}while(!res);
do
{
//Get the address
address = getString("Enter Address: ");
//validate the address
//res = validateAddress(address);
}while(!res);
do
{
//Get the phone
phone = getString("Enter Phone: ");
//validate the phone
res = validatePhone(phone);
}while(!res);
/* cout << endl << endl << endl;
//Convert the name to all uppercase
upperName = convertToUpper(name);
//Display the fields
displayFields(upperName,address,phone);*/
delete[] name;
delete [] address;
delete[] phone;
return 0;
}
//Function implementation goes here
bool validateName(char* name)
{
//variable declaration and initialization
int i = 0;
for (i = 0; name[i] != NULL; i++)
{
//if not an alpha
if (isalpha(name[i]) == 0)
{
//if not a space
if (isspace(name[i]) == 0)
{
return(false);
}
}
}
return(true);
}
char* getString(char* prompt)
{
char buffer [255];
int i;
char* name=NULL;
cout<<"Enter Name: ";
cin.getline(buffer, 255);
name = new char[strlen(buffer) + 1];
strcpy(name,buffer);
char* address=NULL;
cout<<"Enter Address: ";
cin.getline(buffer,255);
address= new char[strlen(buffer) +1];
strcpy(address,buffer);
char* phone = NULL;
cout<<"Enter Phone: ";
cin.getline(buffer,255);
phone= new char[strlen(buffer) +1];
strcpy(phone,buffer);
}
bool validateAddress(char* address)
{
int i = 0;
for (i = 0; address[i] != NULL; i++)
{
//if not an alpha
if (isalnum(address[i]) == 0)
{
//if not a space
if (isspace(address[i]) == 0)
{
return(false);
}
}
}
return(true);
}
bool validatePhone(char* phone)
{
int i = 0;
for (i = 0; phone[i] != NULL; i++)
{
//if not an alpha
if (isdigit(phone[i]) == 0)
{
return(false);
}
}
return(true);
}
/*char* convertToUpper(char* string)
{
}
void displayFields(char* name, char* address, char* phone)
{
}
*/
|