Search this site
Embedded Files
Skip to main content
Skip to navigation
Help Center (COVID-19)
Home
Introduction
Objective
Motivation
News
Documentation
Expected Outcome
Reference
Source Code
Contact Information
Help Center (COVID-19)
Home
Introduction
Objective
Motivation
News
Documentation
Expected Outcome
Reference
Source Code
Contact Information
More
Home
Introduction
Objective
Motivation
News
Documentation
Expected Outcome
Reference
Source Code
Contact Information
Source Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
using namespace std;
struct node
{
string date;
int test, cases, recovered, death;
struct node *next;
};
typedef struct node node;
node *corona = NULL;
void swap(node **head, node *node2)
{
node *current;
if (*head == NULL || (*head)->date > node2->date)
{
node2->next = *head;
*head = node2;
}
else
{
current = *head;
while (current->next != NULL && current->next->date <= node2->date)
{
current = current->next;
}
node2->next = current->next;
current->next = node2;
}
}
void sort(node **head)
{
node *sorted = NULL;
node *current = *head;
while (current != NULL)
{
node *next = current->next;
swap(&sorted, current);
current = next;
}
*head = sorted;
}
void insert(node **head, string date, int test, int cases, int recovered, int death)
{
node *node2 = new node();
node2->date = date;
node2->test = test;
node2->cases = cases;
node2->recovered = recovered;
node2->death = death;
node2->next = (*head);
(*head) = node2;
}
void new_report()
{
string date;
int N, test, cases, recovered, death;
cout << "\nHow many reports do you want to add: ";
cin >> N;
for (int i = 0; i < N; i++)
{
cout << endl;
cout << "Date of report (eg: 07/11/20): ";
cin.ignore();
cin >> date;
cout << "Number of New Tests: ";
cin >> test;
cout << "Number of New Identified: ";
cin >> cases;
cout << "Number of Recovery: ";
cin >> recovered;
cout << "Number of Death: ";
cin >> death;
insert(&corona, date, test, cases, recovered, death);
}
sort(&corona);
}
void update_report(node **head)
{
bool found = false;
string date;
int test, cases, recovered, death;
cout << endl;
cout << "\nDate of report to Update (eg: 07/11/20): ";
cin.ignore();
cin >> date;
node *current = *head;
while (current != NULL)
{
if (current->date == date)
{
found = true;
cout << "Number of New Tests: ";
cin >> test;
cout << "Number of New Identified: ";
cin >> cases;
cout << "Number of Recovery: ";
cin >> recovered;
cout << "Number of Death: ";
cin >> death;
current->test = test;
current->cases = cases;
current->recovered = recovered;
current->death = death;
cout << "\nUpdated successfully." << endl;
return;
}
current = current->next;
}
if (!found)
cout << "\nNo report of " << date << " found in database." << endl;
}
void delete_report(node **head)
{
string date;
cout << "\nDate of report to Delete (eg: 07/11/20): ";
cin.ignore();
cin >> date;
node *temp = *head, *prev;
if (temp != NULL && temp->date == date)
{
*head = temp->next;
free(temp);
cout << "\nDeleted successfully.\n" << endl;
return;
}
while (temp != NULL && temp->date != date)
{
prev = temp;
temp = temp->next;
}
if (temp == NULL)
{
cout << "\nNot found!\n" << endl;
return;
}
prev->next = temp->next;
free(temp);
cout << "\nDeleted successfully.\n" << endl;
}
void view_report(node **head)
{
int N;
cout << "\nChoose an option: " << endl;
cout << "1. View report of one specific date" << endl;
cout << "2. View report of multiple days\n"
<< endl;
cout << "Enter an Option: ";
cin >> N;
if (N == 1)
{
bool printed = false;
string date;
cout << endl;
cout << "\nDate of report to Show (eg: 07/11/20): ";
cin.ignore();
cin >> date;
node *current = *head;
while (current != NULL)
{
if (current->date == date)
{
cout << endl;
cout << ">> Report of " << current->date << ':' << endl;
cout << "\tNew Test: " << current->test << endl;
cout << "\tNew Indentified: " << current->cases << endl;
cout << "\tNew Recovered: " << current->recovered << endl;
cout << "\tNew Death: " << current->death << endl;
printed = true;
break;
}
current = current->next;
}
if (!printed)
cout << "\nNo result found!" << endl;
}
else if (N == 2)
{
bool printed = false;
string date1, date2;
cout << "\nDate of report Starting From (eg: 07/11/20): ";
cin.ignore();
cin >> date1;
cout << "Date of report Ending to (eg: 07/11/20): ";
cin.ignore();
cin >> date2;
node *current = *head;
while (current != NULL)
{
if (current->date >= date1 && current->date <= date2)
{
cout << endl;
cout << "Report of " << current->date << ':' << endl;
cout << "\tNew Test: " << current->test << endl;
cout << "\tNew Identified: " << current->cases << endl;
cout << "\tNew Recovered: " << current->recovered << endl;
cout << "\tNew Death: " << current->death << endl;
printed = true;
}
if (current->date > date2)
break;
current = current->next;
}
if (!printed)
cout << "\nNo result found!\n" << endl;
}
else
{
cout << "\nInvalid option! Please try again.\n" << endl;
view_report(&corona);
}
}
void view_summary(node **head)
{
int ttest = 0, tcases = 0, trecovered = 0, tdeath = 0;
node *temp = *head;
while (temp != NULL)
{
ttest += temp->test;
tcases += temp->cases;
trecovered += temp->recovered;
tdeath += temp->death;
temp = temp->next;
}
cout << "\nOverall Summary Report:\n" << endl;
cout << "Total Sample Tests: " << ttest << endl;
cout << "Total Identified: " << tcases << endl;
cout << "Total Recoveries: " << trecovered << endl;
cout << "Total Deaths: " << tdeath << endl;
cout << "\nSample Tests vs. Total Identified Ratio: " << fixed << setprecision(2) << ((tcases * 100.0) / ttest) << '%' << endl;
}
int main()
{
int option = 0;
while (option != 6)
{
cout << "Choose an option:\n" << endl;
cout << "1. Add new report in database" << endl;
cout << "2. Update report from database" << endl;
cout << "3. Delete report from database" << endl;
cout << "4. View report of specific date(s)" << endl;
cout << "5. View overall summary report" << endl;
cout << "6. Exit\n" << endl;
cout << "Enter your option: ";
cin >> option;
if (option > 6 || option < 1)
{
cout << "\nInvalid option! Please try again.\n" << endl;
option = 0;
continue;
}
else if (option == 1)
new_report();
else if (option == 2)
update_report(&corona);
else if (option == 3)
delete_report(&corona);
else if (option == 4)
view_report(&corona);
else if (option == 5)
view_summary(&corona);
else if (option == 6)
break;
}
return 0;
}
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse