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
|
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include "Customers.h"
#include "dvdlist.h"
#include "mainfunctionlist.h"
using namespace std;
void initCustomersList(ListC *l){
l->head=NULL;
}
int insertAtHeadCustomers(ListC *l){
Customers *newnode, *cur;
newnode=(Customers*) malloc(sizeof(Customers));
if (newnode==NULL) return 0;
cout<<"Give Customer Name:";
gets(newnode->cstname);fflush(stdin);
cout<<"Give Customer Surname:";
gets(newnode->cstsrname);fflush(stdin);
cout<<"Give Customer ID:";
cin>>newnode->cstID;fflush(stdin); while(newnode->cstID==0) {cout<<"You cant give Zero for ID.Try again"; cin>>newnode->cstID;fflush(stdin);}
newnode->next=l->head;
l->head=newnode;cur=newnode->next;
while(cur!=NULL){
if(cur->cstID==newnode->cstID) {cout<<"Customer ID already exist.Try again:";cin>>newnode->cstID;fflush(stdin);}
cur=cur->next;
}
return 1;
}
void displayList(const ListC *l){
Customers *cur;
cur=l->head;
while (cur!=NULL){
cout<<"Customer Name is:"<<cur->cstname<<endl;
cout<<"Customer Surname is:"<<cur->cstsrname<<endl;
cout<<"Customer ID is:"<<cur->cstID<<endl;
cur=cur->next;
cout<<endl;
}
free(cur);
}
int assortListofCustomers(ListC *l,int key){
Customers *cur;
int x,z,temp,guard=0;
char temp1[NameLength],temp2[NameLength];
cur=l->head;
//f8inousa
for(x=0;x<key;x++)
while(cur->next!=NULL) {
z=strcmp((cur->cstname),((cur->next)->cstname));
if(z>0){//kata onoma
temp=cur->cstID;
strcpy(temp1,cur->cstname);
strcpy(temp2,cur->cstsrname);
cur->cstID=((cur->next)->cstID);
strcpy(cur->cstname,((cur->next)->cstname));
strcpy(cur->cstsrname,((cur->next)->cstsrname));
((cur->next)->cstID)=temp;
strcpy(((cur->next)->cstname),temp1);
strcpy(((cur->next)->cstsrname),temp2); guard++;
}
else if(z==0){
z=strcmp((cur->cstsrname),((cur->next)->cstsrname));
if(z>0){//kata epitheto an kapoio onoma einai idio
temp=cur->cstID;
strcpy(temp1,cur->cstname);
strcpy(temp2,cur->cstsrname);
cur->cstID=((cur->next)->cstID);
strcpy(cur->cstname,((cur->next)->cstname));
strcpy(cur->cstsrname,((cur->next)->cstsrname));
((cur->next)->cstID)=temp;
strcpy(((cur->next)->cstname),temp1);
strcpy(((cur->next)->cstsrname),temp2);guard++;
}
}
cur=cur->next;
}
return guard;
}
int De_ListofCustomers(ListC *l,int key){
Customers *cur, *prev;
//if(l->head==NULL) return 0;
prev=NULL;cur=l->head;
while (cur!=NULL && cur->cstID!=key){
prev=cur;
cur=cur->next;
}
if (cur==NULL) return 0;
if (prev==NULL) l->head=l->head->next;
else prev->next=cur->next;
free(cur);
return 1;
}
void printfCustomerMovies(ListC *l,ListD *dvds){
Customers *test;
dvdtype *cur;
char name[NameLength],srname[NameLength];
int id=0;
cur=dvds->head;
test=l->head;
if(test==NULL) cout<<"There are no customers registered";
else {
cout<<"Give me customer name :";
gets(name);fflush(stdin);cout<<"Give me customer surname :"; gets(srname);fflush(stdin);
while(test!=NULL) {
if(strcmp(test->cstname,name)==0 && strcmp(test->cstsrname,srname)==0) id=test->cstID;
test=test->next;
}
if(cur==NULL) cout<<"There are no registered movies";
cout<<"Movies owned to :";cout<<name << srname<<endl;
while(cur!=NULL){
cout<<cur->title<<endl;
cur=cur->next;
}
}
}
|