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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
//please work
//yues you ailly program
//
//
#include "stdafx.h"
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <string>
#include <functional>
using namespace std;// bad habit, unlearn doing this
bool isValidtitle();
bool isValidName();
bool validate();
int largetgrp();
string ratingscal();
void pooratings();
string title[10];
string name[10];
string telno[10];
int groupsize[10];
int ratin[10];
int i = 0;
int temp = 0;
int poor =0; //poor rating
int good = 0; //good rating
int excellent =0;//excellent rating
int main()
{
string answer;
cout << "do you want to enter a customer questionaire ? y for yes and n for no" << endl;
cin >> answer;
if (answer == "y")
while (answer != "n"){
cout << "please enter title: Mr, Miss or Mrs" << endl;//end to fix input error
getline(cin, title[i]);
if(!isValidtitle(title[i]));
{cerr << "*** Invalid title! ***\n";
cout << "please enter valid title" << endl;
getline(cin, title[i]);
}
cout << "Please enter customer name" << endl;
getline(cin, name[i]);
if (!isValidName(name[i]))
{cerr << "*** Invalid name! ***\n";
cout << "please enter valid name" << endl;
getline(cin, name[i]);
}
cout << "Please enter tel no" << endl;
cin >> telno[i];
while (validate(telno[i]) == false)
{
cout << "please enter valid tel no\n";
cin >> telno[i];
}
cout << "Please enter group size" << endl;
cin >> groupsize[i];
while (!(isdigit (groupsize[i])) && groupsize[i] > 20)
{ cerr << "*** Invalid group size! ***\n";
cout << "please enter valid number" << endl;
cin >>groupsize[i];
}
cout << "Please enter rating" << endl;
cin >> ratin[10];
while (!(isdigit (ratin[i])) && ratin[i] > 10)
{ cerr << "*** Invalid ratin! ***\n";
cout << "please enter valid nnumber" << endl;
cin >> ratin[i];
}
cout << "do you want to enter another customer questionaire ? y for yes and n for no" <<endl;
cin.ignore();
cin.clear();
cin >> answer;
}
int largetgrp();//largest grouop misspelt
string ratingscal(); //display
void pooratings(); // poor ratings display function
system ("pause");
return 0;
}
//validating title function
bool isValidtitle(string title)
{
return all_of(title.begin(), title.end(),
[](char ch) { return (isalpha(ch)); });
}
// validating name function
bool isValidName(string name)
{
return all_of(name.begin(), name.end(),
[](char ch) { return (isalpha(ch)); });
}
//validating tel number function
bool validate(string s)
{
for (int i = 0; i < s.size(); i++)
{
if (isalpha(s[i]))
{
return false;
}
if (isspace(s[i]))
{
return false;
}
if (ispunct(s[i]))
{
return false;
}
if (s.length() != 11)
{
return false;
}
}
}
//searching for largest group size function
int largetgrp(int groupsize[10])
{
int temp = 0;
for(int i=0;i<5;i++)
{
if(groupsize[i]>temp)
{
temp=groupsize[i];
}
}
cout << "The biggest group was: " << temp << endl;
return temp;
}
//calculating and displaying ratings.
string ratingscal(int ratin[10])
{
int pooratings = 0;
pooratings = poor++;
int goodratings = 0;
goodratings = good++;
int execellentratings = 0;
execellentratings = excellent++;
for(int i=0;i<10;i++)
if (ratin[i] == 1 || ratin[i] == 2 || ratin[i] == 3)
{
poor++; // poor ratinng
}
if (ratin[i] == 4 || ratin[i] == 5 || ratin[i] == 6)
{
good++; // good ratinng
}
else if (ratin[i] == 7 || ratin[i] == 8 || ratin[i] == 9 || ratin[i] == 9)
{
excellent++; // excellent ratinng
}
cout << "number of poor ratings: " << pooratings << endl;
cout << "number of good ratings: " << goodratings << endl;
cout << "number of excellent ratings: " << execellentratings << endl;
}
void pooratings(string title[], string name[], string telno[], int groupsize[], int ratin[])
{
cout << " the following are the groups which have given poor ratings" << endl;
for(int i=0;i<10;i++)
{
if (ratin[i] <= 3)
{
cout << "contact name: " << title[i] << " " << name[i] << endl;
cout << "Telphone Number: " << telno <<endl;
cout << "rating: " << ratin << endl;
}
}
return 0;
}
|