CS207-HW3/main.cpp

74 lines
1.8 KiB
C++
Raw Normal View History

2024-12-04 08:51:16 +00:00
#include "Clinic.cpp"
#include "Patient.hpp"
#include "linkedList.cpp"
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <optional>
#include <sstream>
#include <sys/types.h>
int main() {
// this program implements the sieve of Erathosthenes using linked lists
// it does not use/test all the list functions
List primes{nullptr, nullptr};
for (int i = 2; i <= 20; i++) {
primes.appendList(i);
}
node *p = primes.head;
while (p != primes.tail) {
int prime = p->data;
int tailData = primes.tail->data;
for (int composite = 2 * prime; composite <= tailData; composite += prime) {
primes.removeFromList(
composite); // if the composite is not in the list, nothing happens
}
p = p->next;
}
std::cout << primes;
// testing copy
List primes_copy(primes);
std::cout << "primes: " << primes;
std::cout << "primes: " << primes_copy + 1;
std::cout << "primes+primes: " << primes_copy + primes_copy;
// should return 5
std::cout << "primes[2] = ";
std::cout << primes_copy[2].data << std::endl;
return 0;
}
// int main() {
// Clinic clinic("patients.txt");
// std::cout << "Welcome to patient management\n\n";
// // run util main_menu recieves a non-exit value
// MenuChoice choice;
// Patient patient{};
// std::string reading_string;
// std::string input_string;
// while (1) {
// choice = clinic.menu_main();
// switch (choice) {
// case MenuChoice::NewPatient:
// clinic.menu_add_new_patient();
// break;
// case MenuChoice::NewVisit:
// clinic.menu_add_vist();
// break;
// case MenuChoice::DisplayPatient:
// clinic.menu_patient_info();
// break;
// case MenuChoice::Quit:
// return 0;
// break;
// }
// }
// return 0;
// }