School Commit Init
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#include "domain.h"
|
||||
#include "repository.h"
|
||||
#include "controller.h"
|
||||
#include "UI.h"
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
UI::UI(){
|
||||
this->_controller.add("Orange","123",100,true);
|
||||
this->_controller.add("Digi","124",200,false);
|
||||
this->_controller.add("Vodafone","125",300,true);
|
||||
}
|
||||
|
||||
UI::~UI(){
|
||||
|
||||
}
|
||||
|
||||
void UI::run(){
|
||||
char option;
|
||||
while(true){
|
||||
printf("1. Add bill\n");
|
||||
printf("2. Show all bills\n");
|
||||
printf("3. Show all paid bills\n");
|
||||
printf("4. Exit\n");
|
||||
option=fgetc(stdin);
|
||||
while (fgetc(stdin)!='\n');
|
||||
switch(option){
|
||||
case '1':{
|
||||
char company_name[100];
|
||||
char serial_number[100];
|
||||
int sum;
|
||||
bool isPaid;
|
||||
printf("Company name: ");
|
||||
fgets(company_name,100,stdin);
|
||||
company_name[strlen(company_name)-1] = '\0';
|
||||
printf("Serial number: ");
|
||||
fgets(serial_number,100,stdin);
|
||||
serial_number[strlen(serial_number)-1] = '\0';
|
||||
printf("Sum: ");
|
||||
scanf("%d",&sum);
|
||||
printf("Is paid: ");
|
||||
std::cin>>isPaid;
|
||||
bool check = this->_controller.add(company_name,serial_number,sum,isPaid);
|
||||
if(check)
|
||||
printf("Bill added\n");
|
||||
else
|
||||
printf("Bill not added\n");
|
||||
break;
|
||||
}
|
||||
case '2':{
|
||||
auto v = this->_controller.getBills();
|
||||
for (Bill bill : v)
|
||||
std::cout<<bill.company_name()<<";"<<bill.serial_number()<<";"<<bill.sum()<<";"<<bill.isPaid()<<std::endl;
|
||||
break;
|
||||
}
|
||||
case '3':{
|
||||
auto v = this->_controller.getPaidBills();
|
||||
int sum=0;
|
||||
for (Bill bill : v){
|
||||
sum+=bill.sum();
|
||||
std::cout<<bill.company_name()<<";"<<bill.serial_number()<<";"<<bill.sum()<<";"<<bill.isPaid()<<std::endl;
|
||||
}
|
||||
std::cout<<"Sum: "<<sum<<std::endl;
|
||||
break;
|
||||
}
|
||||
case '4':
|
||||
return;
|
||||
default:
|
||||
printf("Invalid option");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user