Add files via upload
This commit is contained in:
31
Exámenes Resueltos (Segundo Semestre)/June2017I/ClientList.h
Normal file
31
Exámenes Resueltos (Segundo Semestre)/June2017I/ClientList.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef _CLIENTLIST
|
||||
#define _CLIENTLIST
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
//Constant:
|
||||
const int MAX_CLIENTS = 50;
|
||||
|
||||
|
||||
//Types:
|
||||
typedef struct tClient {
|
||||
std::string login, registerDate, city;
|
||||
int age;
|
||||
};
|
||||
|
||||
typedef struct tClientList {
|
||||
tClient *client[MAX_CLIENTS];
|
||||
int cont;
|
||||
};
|
||||
|
||||
//Functions:
|
||||
void display(tClient& client);
|
||||
bool load(tClientList& list);
|
||||
void show(tClientList list, int&); //Implement using recursion.
|
||||
void free(tClientList& list);
|
||||
|
||||
|
||||
#endif // !_CLIENTLIST
|
@ -0,0 +1,53 @@
|
||||
#include "ClientList.h"
|
||||
using namespace std;
|
||||
|
||||
void display(tClient& client) {
|
||||
cout << right << setw(10) << client.login
|
||||
<< setw(15) << client.registerDate
|
||||
<< setw(5) << client.age << " years"
|
||||
<< setw(10) << client.city << endl;
|
||||
}
|
||||
|
||||
bool load(tClientList& list) {
|
||||
bool loaded = false;
|
||||
ifstream file;
|
||||
int numClients = 0;
|
||||
|
||||
list.cont = 0;
|
||||
|
||||
file.open("clients.txt");
|
||||
if (!file.is_open()) {
|
||||
cout << "Failed to load clients." << endl;
|
||||
}
|
||||
else {
|
||||
file >> numClients;
|
||||
while (!file.fail() && list.cont < numClients) {
|
||||
list.client[list.cont] = new tClient;
|
||||
file >> list.client[list.cont]->login;
|
||||
file >> list.client[list.cont]->registerDate;
|
||||
file >> list.client[list.cont]->age;
|
||||
file >> list.client[list.cont]->city;
|
||||
list.cont++;
|
||||
}
|
||||
loaded = true;
|
||||
}
|
||||
file.close();
|
||||
|
||||
return loaded;
|
||||
}
|
||||
|
||||
void show(tClientList list, int& i) {
|
||||
|
||||
if (i < list.cont) {
|
||||
cout << i + 1 << ":";
|
||||
display(*list.client[i]);
|
||||
i++;
|
||||
show(list, i);
|
||||
}
|
||||
}
|
||||
|
||||
void free(tClientList& list) {
|
||||
for (int i = 0; i < list.cont; i++){
|
||||
delete list.client[i];
|
||||
}
|
||||
}
|
48
Exámenes Resueltos (Segundo Semestre)/June2017I/DateList.cpp
Normal file
48
Exámenes Resueltos (Segundo Semestre)/June2017I/DateList.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "DateList.h"
|
||||
using namespace std;
|
||||
|
||||
//Auxiliary functions:
|
||||
void expand(tDateList& list, int& newCapacity);
|
||||
|
||||
void newList(tDateList& list) {
|
||||
list.capacity = 10;
|
||||
list.cont = 0;
|
||||
list.date = new tDate[list.capacity];
|
||||
}
|
||||
|
||||
void insert(tDateList& list, tDate& date) {
|
||||
if (list.cont == list.capacity) {
|
||||
expand(list, list.capacity);
|
||||
}
|
||||
list.date[list.cont] = date;
|
||||
list.cont++;
|
||||
}
|
||||
|
||||
//
|
||||
void expand(tDateList& list, int& newCapacity) {
|
||||
list.capacity += newCapacity;
|
||||
tDate *aux = new tDate[list.capacity];
|
||||
|
||||
for (int i = 0; i < list.cont; i++){
|
||||
aux[i] = list.date[i];
|
||||
}
|
||||
|
||||
delete[] list.date;
|
||||
list.date = aux;
|
||||
|
||||
}
|
||||
//
|
||||
|
||||
void display(tDateList& list) {
|
||||
cout << setfill(char('-')) << setw(50) << "\n" << setfill(char(0));
|
||||
for (int i = 0; i < list.cont; i++){
|
||||
display(*list.date[i].client1);
|
||||
display(*list.date[i].client2);
|
||||
cout << "Date in: " << list.date[i].place << ". Rating: " << list.date[i].ratting << endl;
|
||||
cout << setfill(char('-')) << setw(50) << "\n" << setfill(char(0));
|
||||
}
|
||||
}
|
||||
|
||||
void free(tDateList& list) {
|
||||
delete[] list.date;
|
||||
}
|
30
Exámenes Resueltos (Segundo Semestre)/June2017I/DateList.h
Normal file
30
Exámenes Resueltos (Segundo Semestre)/June2017I/DateList.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef _DATELIST
|
||||
#define _DATELIST
|
||||
|
||||
#include "ClientList.h"
|
||||
|
||||
//Constant:
|
||||
|
||||
|
||||
|
||||
//Types:
|
||||
typedef struct tDate {
|
||||
tClient *client1, *client2;
|
||||
std::string place;
|
||||
int ratting;
|
||||
};
|
||||
|
||||
typedef struct tDateList {
|
||||
tDate *date; //Sorted by rating.
|
||||
int cont, capacity;
|
||||
};
|
||||
|
||||
|
||||
//Functions:
|
||||
void newList(tDateList& list);
|
||||
void insert(tDateList& list, tDate& date); //If there are no more free slots add 10 more slots.
|
||||
void display(tDateList& list);
|
||||
void free(tDateList& list);
|
||||
|
||||
|
||||
#endif // !_DATELIST
|
BIN
Exámenes Resueltos (Segundo Semestre)/June2017I/June2017I.pdf
Normal file
BIN
Exámenes Resueltos (Segundo Semestre)/June2017I/June2017I.pdf
Normal file
Binary file not shown.
@ -0,0 +1,9 @@
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#ifndef DBG_NEW
|
||||
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
|
||||
#define new DBG_NEW
|
||||
#endif
|
||||
#endif
|
21
Exámenes Resueltos (Segundo Semestre)/June2017I/clients.txt
Normal file
21
Exámenes Resueltos (Segundo Semestre)/June2017I/clients.txt
Normal file
@ -0,0 +1,21 @@
|
||||
5
|
||||
Luis
|
||||
15/06/08
|
||||
27
|
||||
Madrid
|
||||
Ana
|
||||
23/03/02
|
||||
18
|
||||
Avila
|
||||
Maria
|
||||
02/05/14
|
||||
25
|
||||
Burgos
|
||||
Fernando
|
||||
25/09/2015
|
||||
19
|
||||
Madrid
|
||||
Lena
|
||||
21/09/2017
|
||||
18
|
||||
Madrid
|
80
Exámenes Resueltos (Segundo Semestre)/June2017I/main.cpp
Normal file
80
Exámenes Resueltos (Segundo Semestre)/June2017I/main.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
//Exam June 2017 - FP
|
||||
//Groups: I
|
||||
//Fernando M<>ndez Torrubiano
|
||||
|
||||
#include "DateList.h"
|
||||
#include "checkML.h"
|
||||
using namespace std;
|
||||
|
||||
//Auxiliary functions:
|
||||
int menu();
|
||||
|
||||
int main() {
|
||||
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //Shows memory leaks.
|
||||
|
||||
tClientList clients;
|
||||
tDateList dates;
|
||||
tDate date;
|
||||
int c1, c2;
|
||||
int opc = -1, i = 0;
|
||||
|
||||
if (load(clients)) {
|
||||
newList(dates);
|
||||
while (opc != 0) {
|
||||
opc = menu();
|
||||
switch (opc){
|
||||
case 1:
|
||||
show(clients, i);
|
||||
break;
|
||||
case 2:
|
||||
show(clients, i);
|
||||
cout << "Clients: ";
|
||||
cin >> c1;
|
||||
cin >> c2;
|
||||
date.client1 = clients.client[c1 - 1];
|
||||
date.client2 = clients.client[c2 - 1];
|
||||
cout << "Date<EFBFBD>s place: ";
|
||||
cin >> date.place;
|
||||
do {
|
||||
cout << "Date<EFBFBD>s rating [0-5]: ";
|
||||
cin >> date.ratting;
|
||||
} while (date.ratting < 0 || date.ratting > 5);
|
||||
insert(dates, date);
|
||||
break;
|
||||
case 3:
|
||||
cout << "Date list: " << endl;
|
||||
display(dates);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << "End of program." << endl;
|
||||
}
|
||||
|
||||
free(clients);
|
||||
free(dates);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int menu() {
|
||||
int opc = 0;
|
||||
|
||||
cout << setfill(char('-')) << setw(50) << "\n" << setfill(char(0));
|
||||
cout << "1.-Display client list." << endl;
|
||||
cout << "2.-New date." << endl;
|
||||
cout << "3.-Display dates." << endl;
|
||||
cout << "0.-EXIT." << endl;
|
||||
cout << setfill(char('-')) << setw(50) << "\n" << setfill(char(0));
|
||||
|
||||
do {
|
||||
cout << "Choose an option: ";
|
||||
cin >> opc;
|
||||
} while (opc < 0 || opc > 3);
|
||||
|
||||
return opc;
|
||||
}
|
Reference in New Issue
Block a user