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 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
#include <fstream>
#include <string>
#include <iostream>
#include "conio.h"
using namespace std;
struct name
{
string namef;
string namel;
};
struct infof
{
int marks;
string category;
string group;
};
struct form
{
int formno;
int session;
name personal;
infof data;
};
struct grade
{
int om;
int army;
int def;
};
struct infom
{
int listno;
grade quota;
string group;
};
struct list
{
int session;
infom data;
};
struct infoi
{
int listno;
string quota;
string group;
};
struct input
{
int session;
infoi category;
};
void appendStudentToFile(const char *fileName, form &student)
{
ofstream fs(fileName, ios::app);
fs << student.formno << '\t'
<< student.personal.namef << '\t'
<< student.personal.namel << '\t'
<< student.data.marks << '\t'
<< student.data.group << '\t'
<< student.data.category << '\t'
<< student.session << '\n';
}
// Return true if str is in the string of possibilities.
// Possibilities must be space separated. Str can't have any spaces in it
bool isOneOf(const string &str, const string &possibilities)
{
// add spaces before and after both strings, then search for the
// modified key in the string. For example, if str is "hello" and
// possibilities is "hello world" then we end of searching for "
// hello " in " hello world ". By adding the spaces, we ensure
// that it won't match a substring, or miss the first or last
// possibility
string p = " " + possibilities + " ";
string key = " " + str + " ";
return p.find(key) != string::npos;
}
int
menu_generate()
{
cin.clear();
cin.ignore(numeric_limits < streamsize >::max(), '\n');
start_generate:
system("cls");
form student;
list merit;
input generate;
string col[2], in, record;
char cmd;
system("cls");
cout << "\n\t\t Generate" << endl;
cout << "_________________________________________" << endl;
cout << "Back\t\t\t\t\tX\n" << endl;
cout << "\n Hint: The Capital Letters Represents\n\tthe Input Commands." << endl;
cout << "\n\tSession: ";
getline(cin, in);
if (in == "b") {
system("cls");
return (0);
}
if (in == "x") {
system("cls");
exit(0);
}
generate.session = stoi(in);
if (!((generate.session >= 0) && (generate.session <= 9999))) {
cout << "\t ERROR! Session out of bound.";
getch();
system("cls");
goto start_generate;
}
cout << "\tMerit List: ";
getline(cin, in);
if (in == "b") {
system("cls");
return (0);
}
if (in == "x") {
system("cls");
exit(0);
}
generate.category.listno = stoi(in);
if (!((generate.category.listno >= 1) && (generate.category.listno <= 3))) {
cout << "\t ERROR! MeritList out of bound.";
getch();
system("cls");
goto start_generate;
}
cout << "\n\t Quota: ";
getline(cin, in);
if (in == "b") {
system("cls");
return (0);
}
if (in == "x") {
system("cls");
exit(0);
}
generate.category.quota = in;
if (!isOneOf(generate.category.quota, "civ om army def gov")) {
cout << "\t ERROR! Quota out of bound.";
getch();
system("cls");
goto start_generate;
}
cout << "\t Group: ";
getline(cin, in);
if (in == "b") {
system("cls");
return (0);
}
if (in == "x") {
system("cls");
exit(0);
}
generate.category.group = in;
if (!isOneOf(generate.category.group, "cs econ stats engg med")) {
cout << "\t ERROR! Group out of bound.";
getch();
system("cls");
goto start_generate;
}
cout << "\n\t Are you Sure? (y/n): ";
in = getche();
if (!(in == "y"))
goto start_generate;
ifstream fetch_candidate("candidates.txt", ios::in);
if (!fetch_candidate) {
cout << "\tERROR! \'candidates.txt\' Not Found." << endl;
getch();
system("cls");
return (0);
}
while (fetch_candidate >> student.formno) {
getline(fetch_candidate >> ws, student.personal.namef, '\t');
getline(fetch_candidate >> ws, student.personal.namel, '\t');
fetch_candidate >> student.data.category
>> student.data.group >> student.data.marks >> student.session;
if (generate.session != student.session) {
continue; // skip it
}
ifstream fetch_merit("merit.txt", ios::in);
if (!fetch_merit) {
cout << "\n\t ERROR! \'merit.txt\' Not Found.";
getch();
system("cls");
return (0);
}
while (fetch_merit >> merit.session
>> merit.data.listno
>> merit.data.group
>> merit.data.quota.om
>> merit.data.quota.army >> merit.data.quota.def) {
if (generate.session == merit.session &&
generate.category.listno == merit.data.listno &&
generate.category.group == merit.data.group &&
generate.category.group == student.data.group) {
if ((((generate.category.quota == "civ")
|| (generate.category.quota == "om"))
&& (student.data.category == "civ"))
&& (student.data.marks >= merit.data.quota.om)) {
appendStudentToFile("LISTOM.txt", student);
}
if (((generate.category.quota == "def") || (generate.category.quota == "gov")) &&
(student.data.category == generate.category.quota) &&
(student.data.marks >= merit.data.quota.def)) {
appendStudentToFile("LISTDefGov.txt", student);
}
if (((generate.category.quota == "army")
&& (student.data.category == "army"))
&& (student.data.marks >= merit.data.quota.army)) {
appendStudentToFile("LISTArmy.txt", student);
}
}
}
}
cout << "\n\tMerit List Successfully Generated!";
getch();
goto start_generate;
}
|