commit 811a37a5192ec79fd6b852a3fd17eab7fee53203
parent 2bb33028bf41a348756ee3d05ab6a1985a265716
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Wed, 22 May 2024 00:29:06 -0300
add `pre` and `post` conditions
Diffstat:
1 file changed, 86 insertions(+), 1 deletion(-)
diff --git a/parciales/2021-1C-3p/main.cpp b/parciales/2021-1C-3p/main.cpp
@@ -17,6 +17,9 @@ private:
bool captionsActive;
public:
+ /**
+ * post: inicializa `App`
+ */
App() {
this->size = 0;
this->type = UNKNOWN;
@@ -24,6 +27,9 @@ public:
this->captionsActive = false;
}
+ /**
+ * post: inicializa `App` con atributo `name` pasado como argumento
+ */
App(std::string name) {
this->name = name;
this->size = 0;
@@ -32,6 +38,9 @@ public:
this->captionsActive = false;
}
+ /**
+ * post: inicializa `App` con los atributos pasados como argumento
+ */
App(std::string name, float size, appType type,
bool appRequiresInternet, bool captionsActive) {
this->name = name;
@@ -41,32 +50,56 @@ public:
this->captionsActive = captionsActive;
}
+ /**
+ * post: libera la memoria
+ */
virtual ~App() {}
+ /**
+ * post: devuelve el atributo `name`
+ */
std::string getName() {
return this->name;
}
+ /**
+ * post: devuelve el atributo `type`
+ */
appType getAppType() {
return this->type;
}
+ /**
+ * post: asigna al atributo `name` aquel pasado como argumento
+ */
void setName(std::string name) {
this->name = name;
}
+ /**
+ * post: asigna al atributo `captionsActive` el valor de `status`
+ */
void setCaptions(bool status) {
this->captionsActive = status;
}
+ /**
+ * post: devuelve el estado de `captionsActive`
+ */
bool getCaptions(bool status) {
return this->captionsActive;
}
+ /**
+ * post: cambia al valor opuesto `captionsActive`
+ */
void toggleCaptions() {
this->captionsActive = !this->captionsActive;
}
+ /**
+ * post: devuelve el valor del atributo `appRequiresInternet`
+ */
bool requiresInternet() {
return this->appRequiresInternet;
}
@@ -81,6 +114,9 @@ private:
bool internetConnected;
public:
+ /**
+ * post: inicializa la clase `SmartTV`
+ */
SmartTV() {
this->appsList = new Vector<App*>;
this->currentApp = NULL;
@@ -89,6 +125,10 @@ public:
this->appsInstalledCount = 0;
}
+ /**
+ * post: inicializa `SmartTV` con el valor de `diskSize` a aquel pasado como
+ * argumento
+ */
SmartTV(float diskSize) {
this->appsList = new Vector<App*>;
this->currentApp = NULL;
@@ -97,6 +137,9 @@ public:
this->appsInstalledCount = 0;
}
+ /**
+ * post: libera la memoria de `SmartTV` y todas las instancias de `App`
+ */
virtual ~SmartTV() {
for(size_t i = 0; i < this->appsList->getSize(); ++i) {
delete this->appsList->getAtIndex(i);
@@ -104,12 +147,19 @@ public:
delete this->appsList;
}
+ /**
+ * post: agrega una aplicacion a `appsList`
+ */
void addApp(std::string name) {
App *newApp = new App(name);
this->appsList->append(newApp);
this->appsInstalledCount++;
}
+ /**
+ * post: agrega una aplicacion a `appsList` con los atributos recibidos como
+ * argumento
+ */
void addApp(std::string name, float size, appType type, bool requiresInternet) {
try {
this->getAppByName(name);
@@ -121,10 +171,17 @@ public:
}
}
+ /**
+ * post: devuelve el valor de `appsInstalledCount`
+ */
unsigned int getAppsInstalledCount() {
return this->appsInstalledCount;
}
+ /**
+ * post: devuelve un puntero a la aplicacion en la posicion `index`
+ * de `appsList`
+ */
App *getAppByIndex(unsigned int index) {
try {
return this->appsList->getAtIndex(index);
@@ -133,6 +190,10 @@ public:
}
}
+ /**
+ * pre: la aplicacion debe existir en `appsList` si no arroja una excepción
+ * post: devuelve un puntero a la aplicacion cuyo nombre es `name`
+ */
App *getAppByName(std::string name) {
for(size_t i = 0; i < this->appsList->getSize(); ++i) {
App *tmp = this->appsList->getAtIndex(i);
@@ -143,6 +204,10 @@ public:
throw "the app `" + name + "` is not installed";
}
+ /**
+ * pre: no hay una aplicacion corriendo, si no arroja una excepción
+ * post: apunta `currentApp` a la aplicacion con nombre `name`
+ */
void startApp(std::string name) {
if(currentApp != NULL) {
throw "there is an app running already";
@@ -161,10 +226,18 @@ public:
}
}
+ /**
+ * pre: hay una aplicacion corriendo
+ * post: devuelve un puntero a la aplicacion que está corriendo actualmente
+ */
App *getCurrentApp() {
return this->currentApp;
}
+ /**
+ * pre: hay una aplicacion corriendo
+ * post: asigna el valor de `currentApp` a `NULL`
+ */
void closeApp(std::string name) {
if(currentApp == NULL) {
throw "there is no app running";
@@ -173,14 +246,24 @@ public:
currentApp = NULL;
}
+ /**
+ * post: asigna a `internetConnected` el valor `true`
+ */
void internetConnect() {
this->internetConnected = true;
}
+ /**
+ * post: asigna a `internetConnected` el valor `false`
+ */
void internetDiconnect() {
this->internetConnected = false;
}
+ /**
+ * pre: hay una aplicación ejecutandose y es de tipo `VIDEO`
+ * post: ejecuta el metodo `toggleCaptions` de la aplicacion en ejecución
+ */
void toggleCaptions() {
App *runningApp = this->currentApp;
if((runningApp != NULL) && (runningApp->getAppType() == VIDEO)) {
@@ -201,14 +284,16 @@ void printTvStatus(SmartTV *tv) {
}
int main (void) {
- SmartTV *tv = new SmartTV(8000); // inicializa tv con disco de 8GB
+ SmartTV *tv = new SmartTV(8000); // inicializa tv con disco de 8GB (8000MB)
tv->internetConnect();
tv->addApp("X", 150, SOCIAL, true);
tv->addApp("youtube", 258, VIDEO, true);
+ tv->addApp("spotify");
tv->startApp("youtube");
printTvStatus(tv);
+ std::cout << std::endl;
tv->closeApp("youtube");
printTvStatus(tv);