Вы находитесь на странице: 1из 7

#include

#include
#include
#include
#include

<iostream>
<Windows.h>
<process.h>
<sstream>
<stdio.h>

using namespace std;


#define chair 0
#define stool 1
#define laptop 0
#define mobile 1
#define male 0
#define female 1
int furniture[15][3] = { { chair,10000,15 },{ stool,1200,15 } };
int it[15][3] = { { laptop , 50000,15 } ,{ mobile , 10000,15 } };
int bought;
#define exist -1
#define donotexist -2
struct customer
{
int id;
string name;
string gender;
int totalitems=0;
int category;
float discount;
};
customer listofcustomer[100];
int list_check = donotexist;
int element_counter = 0;
int list[100];
int copy_list[100];
//functions
void createobjectarray(int num);
bool wrong_char(char num);
void menu();
void addelements();
void createlist();
void deletelist();
void clearlist();
void copy();
void display();
bool int_check = false;
int main() {
menu();
exit:
system("pause");
}
stringstream ss;
void menu() {
int choice;
char y_n;
while (1) {

cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
do {

<<
<<
<<
<<
<<
<<
<<
<<
<<
<<
<<

"Press
"Press
"Press
"Press
"Press
"Press
"Press
"Press
"Press
"Press
"Press

1 of create list : " << endl;


2 to delete list : " << endl;
3 to copy list : " << endl;
4 to clear list : " << endl;
5 to display list : " << endl;
6 to add elements to list(append) : " << endl;
6 to update by position : " << endl;
7 to update list by value : " << endl;
8 to swap values by position : " << endl;
9 to swap values by value : " << endl;
-1 to exit " << endl;

cout << "Enter your choice : ";


cin >> choice;
int_check = cin.fail();
if (cin.fail() == true) {
cout << "Entry should be an integer ranging 1-14
" << endl;
}
cin.clear();
cin.ignore(100, '\n');
} while (int_check == true);
switch (choice) {
case 1:
system("cls");
if (list_check == exist) {
cout << "List already exists do you want to over
write (y/n)? :";
do {
cin >> y_n;
if (y_n == 'y' || y_n == 'Y') {
system("cls");
createlist();
break;
} if (y_n == 'n' || y_n == 'N') {
system("cls");
break;
}
} while (wrong_char(y_n) == true);
}
else {
createlist();
}
break;
case 2:
system("cls");
if (list_check == donotexist) {
cout << "The list does not exist, create the lis
t first \n";
}
else {
cout << "Are you sure you want to delete the lis
t (y/n) : ";
do {

cin >> y_n;


if (y_n == 'y' || y_n == 'Y') {
system("cls");
deletelist();
break;
} if (y_n == 'n' || y_n == 'N') {
system("cls");
break;
}
} while (wrong_char(y_n) == true);
}
break;
case 3:
system("cls");
if (list_check == donotexist) {
cout << "List does not exists , Create the list
first \n";
}
else {
cout << "Are you sure you want to copy the list
(y/n) : ";
do {
cin >> y_n;
if (y_n == 'y' || y_n == 'Y') {
system("cls");
copy();
break;
} if (y_n == 'n' || y_n == 'N') {
system("cls");
break;
}
} while (wrong_char(y_n) == true);
}
break;
case 4:
system("cls");
if (list_check == donotexist) {
cout << "List does not exist , Create the list f
irst \n";
}
else {
cout << "Are you sure you want to clear the list
(y/n) : ";
do {
cin >> y_n;
if (y_n == 'y' || y_n == 'Y') {
system("cls");
clearlist();
break;
} if (y_n == 'n' || y_n == 'N') {
system("cls");
break;
}
} while (wrong_char(y_n) == true);
}break;

case 5:
system("cls");
if (list_check == donotexist) {
cout << "List does not exist , Create the list f
irst \n";
}
else
display();
break;
case 6:
system("cls");
if (list_check == donotexist) {
cout << "List does not exist, Create the list fi
rst \n";
}
else {
addelements();
}
break;
case -1:
exit(1);
break;
default:
cout << "\n choice should be between 1 - 14 \n";
}
}
}
void createlist() {
int number;
bool repeat = false;
do {
cout << "How many entries you want to add to list : ";
cin >> number;
int_check = cin.fail();
if (cin.fail() == true) {
cout << "Entry should be an integer ranging 1-100" << en
dl;
}
cin.clear();
cin.ignore(100, '\n');
createobjectarray(number);
} while (int_check == true );
//cin >> number;
//bool test = false;
element_counter = number;
for (size_t i = 0; i < number; i++)
{
do {
cout << "Enter the id of customer " << i + 1 << " : ";
cin >> listofcustomer[i].id;
int_check = cin.fail();

if (int_check == true) {
cout << "Entry should be any integer\n\n";
cin.clear();
cin.ignore(256, '\n');
}
if (number > 1 && i > 0) {
repeat = false;
for (int j = 0; j < i; j++) {
if (listofcustomer[j].id == listofcustom
er[i].id) {
cout << "id " << listofcustomer[
i].id << " already exists at " << j + 1 << " index " << endl;
//i--;
repeat = true;
}
}
}
//i--; if (i <= 0) { i = 0; }
} while (int_check == true || repeat == true );
int mf; string s1, s2;
cout << "Enter first name : ";
cin >>s1;
cout << "Enter second name : ";
cin >> s2;
listofcustomer[i].name = s1 + " " + s2;
do {
cout << "Enter your gender :0 for male 1 for female: ";
cin >>mf;
int_check = cin.fail();
if (int_check == true) {
cout << "Entry should be an integer \n\n";
cin.clear();
cin.ignore(256,'\n');
}if (mf > 1 || mf < 0) {
cout << "Out of range choice could be either 0 o
r 1 !\n\n";
}
if (mf == 0) {
listofcustomer[i].gender = "male";
}
if (mf == 1) {
listofcustomer[i].gender = "female";
}
} while (int_check == true || mf >1 || mf < 0);
/*if (number > 1 && i > 0) {
for (int j = 0; j < i; j++) {
if (listofcustomer[j].id == listofcustomer[i].id
) {
cout << "id " << listofcustomer[i].id <<
" already exists at " << j + 1 << " index " << endl;
i--;
}
}
}*/
}
cout << "list of " << number << " numbers is created\n" << endl;

list_check = exist;
}
void deletelist() {
list_check = donotexist;
element_counter = 0;
cout << "List has been successfully deleted \n";
}
void clearlist() {
element_counter = 0;
cout << "List has been successfully cleared " << endl;
}
void copy() {
for (int i = 0; i < element_counter; i++) {
copy_list[i] = list[i];
}
cout << "list has been copid successfully " << endl;
}
void display() {
system("cls");
cout << "+-----------------------------------------------+--------------+" << endl;
cout << "|index\t|\tID\t|\tName\t\t|"<<"\tGender\t|" << endl;
cout << "+-------+---------------+-----------------------+--------------+" << endl;
for (int i = 0; i < element_counter; i++) {
cout << "|" << i + 1 << "\t|\t" << listofcustomer[i].id << "\t|\
t" <<listofcustomer[i].name << "\t|\t"<<listofcustomer[i].gender<<"\t|" << endl;
}
cout << "+-------+---------------+-----------------------+--------------+" << endl;
}
bool wrong_char(char num) {
if (num != 'Y' || num != 'y' || num != 'n' || num != 'N')
{
cout << "Wrong choice \n try again :";
return true;
}
else
return false;
}
void addelements() {
int number;
do {
cout << "How many elements you want to add to list : ";

cin >> number;


int_check = cin.fail();
if (cin.fail() == true) {
cout << "Entry should be an integer ranging 1-14" << end
l;
}
cin.clear();
cin.ignore(100, '\n');
} while (int_check == true);
int old = element_counter;
//cin >> number;
element_counter += number;
for (size_t i = old; i < number + old; i++)
{
//cout << "Enter the number at " << i + 1 << " index: ";
//cin >> list[i];
do {
cout << "Enter the number at " << i + 1 << " index: ";
cin >> list[i];
int_check = cin.fail();
if (int_check == true) {
cout << "Entry should be any integer\n\n";
cin.clear();
cin.ignore(100, '\n');
//i--; if (i <= 0) { i = 0; }
}
} while (int_check == true);
if (number > 1 && i >0) {
for (int j = 0; j < i; j++) {
if (list[j] == list[i]) {
cout << "number " << list[i] << " alread
y exists at " << j + 1 << " index " << endl;
i--;
}
}
}
}
cout << number << " more numbers added to the list\n Total elements in l
ist = " << number + old << endl;
list_check = exist;
}
void createobjectarray(int num) {
for (size_t i = 0; i < num; i++)
{
customer obj;
listofcustomer[i] = obj;
}
}
dekh le kuch help milay to
Chat Conversation End

Вам также может понравиться