initial commit
This commit is contained in:
commit
1f19d82e22
117
.gitignore
vendored
Normal file
117
.gitignore
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/clion
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=clion
|
||||
|
||||
### CLion ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
**/.idea/**/workspace.xml
|
||||
**/.idea/**/tasks.xml
|
||||
**/.idea/**/usage.statistics.xml
|
||||
**/.idea/**/dictionaries
|
||||
**/.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
**/.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
**/.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
**/.idea/**/dataSources/
|
||||
**/.idea/**/dataSources.ids
|
||||
**/.idea/**/dataSources.local.xml
|
||||
**/.idea/**/sqlDataSources.xml
|
||||
**/.idea/**/dynamic.xml
|
||||
**/.idea/**/uiDesigner.xml
|
||||
**/.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
**/.idea/**/gradle.xml
|
||||
**/.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
**/cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
**/.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
**/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
**/.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
**/atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
**/.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
**/.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
**/com_crashlytics_export_strings.xml
|
||||
**/crashlytics.properties
|
||||
**/crashlytics-build.properties
|
||||
**/fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
**/.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
**/.idea/caches/build_file_checksums.ser
|
||||
|
||||
### CLion Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||
**/.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||
**/.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||
**/.idea/**/markdown-navigator.xml
|
||||
**/.idea/**/markdown-navigator-enh.xml
|
||||
**/.idea/**/markdown-navigator/
|
||||
|
||||
# Cache file creation bug
|
||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||
**/.idea/$CACHE_FILE$
|
||||
|
||||
# CodeStream plugin
|
||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||
**/.idea/codestream.xml
|
||||
|
||||
# Azure Toolkit for IntelliJ plugin
|
||||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
||||
**/.idea/**/azureSettings.xml
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/clion
|
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
08_team_project
|
2
.idea/08-team-project.iml
generated
Normal file
2
.idea/08-team-project.iml
generated
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/08-team-project.iml" filepath="$PROJECT_DIR$/.idea/08-team-project.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
1
BinarySearchTree.cpp
Normal file
1
BinarySearchTree.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "BinarySearchTree.h"
|
22
BinarySearchTree.h
Normal file
22
BinarySearchTree.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef INC_08_TEAM_PROJECT_BINARYSEARCHTREE_H
|
||||
#define INC_08_TEAM_PROJECT_BINARYSEARCHTREE_H
|
||||
|
||||
#include "BinaryTree.h"
|
||||
|
||||
template<typename T>
|
||||
class BinarySearchTree: public BinaryTree<T> {
|
||||
private:
|
||||
|
||||
public:
|
||||
BinarySearchTree() : BinaryTree<T>() {};
|
||||
|
||||
~BinarySearchTree() { throw std::logic_error("Not implemented: ~BinarySearchTree()"); };
|
||||
|
||||
void insert(const T &item) { throw std::logic_error("Not implemented: BinarySearchTree.insert()"); };
|
||||
|
||||
void remove(const T &item) { throw std::logic_error("Not implemented: BinarySearchTree.remove()"); };
|
||||
|
||||
BinaryTreeNode<T> *search(const T &item) { return _search(this->root, item); };
|
||||
};
|
||||
|
||||
#endif //INC_08_TEAM_PROJECT_BINARYSEARCHTREE_H
|
1
BinaryTree.cpp
Normal file
1
BinaryTree.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "BinaryTree.h"
|
33
BinaryTree.h
Normal file
33
BinaryTree.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef INC_08_TEAM_PROJECT_BINARYTREE_H
|
||||
#define INC_08_TEAM_PROJECT_BINARYTREE_H
|
||||
|
||||
#include "BinaryTreeNode.h"
|
||||
|
||||
template<typename T>
|
||||
class BinaryTree {
|
||||
private:
|
||||
BinaryTreeNode<T> *root;
|
||||
int size;
|
||||
|
||||
public:
|
||||
BinaryTree() : root(nullptr), size(0) {};
|
||||
|
||||
~BinaryTree() { throw std::logic_error("Not implemented: ~BinaryTree()"); };
|
||||
|
||||
[[nodiscard]] bool isEmpty() const { return size == 0; };
|
||||
|
||||
[[nodiscard]] int getSize() const { return size; };
|
||||
|
||||
void clear() { throw std::logic_error("Not implemented: BinaryTree.clear()"); };
|
||||
|
||||
void preOrder(void visit(const T &)) { throw std::logic_error("Not implemented: BinaryTree.preOrder()"); };
|
||||
|
||||
void postOrder(void visit(const T &)) { throw std::logic_error("Not implemented: BinaryTree.postOrder()"); };
|
||||
|
||||
void inOrder(void visit(const T &)) { throw std::logic_error("Not implemented: BinaryTree.inOrder()"); };
|
||||
|
||||
void printIndented(void visit(const T &, int)) { throw std::logic_error("Not implemented: BinaryTree.printIndented()"); };
|
||||
|
||||
};
|
||||
|
||||
#endif //INC_08_TEAM_PROJECT_BINARYTREE_H
|
11
BinaryTreeNode.h
Normal file
11
BinaryTreeNode.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef INC_08_TEAM_PROJECT_BINARYTREENODE_H
|
||||
#define INC_08_TEAM_PROJECT_BINARYTREENODE_H
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
template<typename T>
|
||||
class BinaryTreeNode {
|
||||
|
||||
};
|
||||
|
||||
#endif //INC_08_TEAM_PROJECT_BINARYTREENODE_H
|
24
CMakeLists.txt
Normal file
24
CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(08_team_project)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(08_team_project main.cpp
|
||||
utils.h
|
||||
utils.cpp
|
||||
BinaryTreeNode.h
|
||||
BinaryTree.cpp
|
||||
BinaryTree.h
|
||||
BinarySearchTree.cpp
|
||||
BinarySearchTree.h
|
||||
HashNode.cpp
|
||||
HashNode.h
|
||||
HashTable.cpp
|
||||
HashTable.h
|
||||
# CPU.cpp
|
||||
CPU.h
|
||||
Stack.cpp
|
||||
Stack.h
|
||||
StackNode.cpp
|
||||
StackNode.h
|
||||
)
|
65
CPU.h
Normal file
65
CPU.h
Normal file
@ -0,0 +1,65 @@
|
||||
#ifndef INC_08_TEAM_PROJECT_CPU_H
|
||||
#define INC_08_TEAM_PROJECT_CPU_H
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
class CPU {
|
||||
private:
|
||||
std::string cpuId;
|
||||
int releaseYear;
|
||||
int coreCount;
|
||||
std::string architecture;
|
||||
double baseClock;
|
||||
|
||||
public:
|
||||
CPU(std::string id, int year, int cores, std::string arch, double clock) :
|
||||
cpuId(std::move(id)),
|
||||
releaseYear(year),
|
||||
coreCount(cores),
|
||||
architecture(std::move(arch)),
|
||||
baseClock(clock) {};
|
||||
|
||||
std::string getCpuId() const;
|
||||
|
||||
int getReleaseYear() const;
|
||||
|
||||
int getCoreCount() const;
|
||||
|
||||
std::string getArchitecture() const;
|
||||
|
||||
double getBaseClock() const;
|
||||
|
||||
void setCpuId(std::string id);
|
||||
|
||||
void setReleaseYear(int year);
|
||||
|
||||
void setCoreCount(int cores);
|
||||
|
||||
void setArchitecture(std::string arch);
|
||||
|
||||
void setBaseClock(double clock);
|
||||
|
||||
// Operator overloads
|
||||
bool operator<(const CPU &rhs) const;
|
||||
|
||||
bool operator>(const CPU &rhs) const;
|
||||
|
||||
bool operator==(const CPU &rhs) const;
|
||||
|
||||
// Friend function declarations
|
||||
friend void display(const CPU &cpu);
|
||||
|
||||
friend void iDisplay(const CPU &cpu, int level);
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, const CPU &cpu);
|
||||
|
||||
friend int key_to_index(const CPU &key, int size);
|
||||
};
|
||||
|
||||
int key_to_index(const CPU &key, int size) {
|
||||
// TODO
|
||||
return key.coreCount % size;
|
||||
};
|
||||
|
||||
#endif //INC_08_TEAM_PROJECT_CPU_H
|
1
HashNode.cpp
Normal file
1
HashNode.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "HashNode.h"
|
10
HashNode.h
Normal file
10
HashNode.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef INC_08_TEAM_PROJECT_HASHNODE_H
|
||||
#define INC_08_TEAM_PROJECT_HASHNODE_H
|
||||
|
||||
template<typename T>
|
||||
class HashNode {
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //INC_08_TEAM_PROJECT_HASHNODE_H
|
1
HashTable.cpp
Normal file
1
HashTable.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "HashTable.h"
|
42
HashTable.h
Normal file
42
HashTable.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef INC_08_TEAM_PROJECT_HASHTABLE_H
|
||||
#define INC_08_TEAM_PROJECT_HASHTABLE_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include "HashNode.h"
|
||||
|
||||
template<typename T>
|
||||
class HashTable {
|
||||
private:
|
||||
int hashSize;
|
||||
int count;
|
||||
HashNode<T> *hashAry;
|
||||
|
||||
public:
|
||||
HashTable() : hashSize(97), count(0) {
|
||||
hashAry = new HashNode<T>[hashSize];
|
||||
};
|
||||
|
||||
~HashTable() { delete[] hashAry; };
|
||||
|
||||
[[nodiscard]] int getCount() const { return count; };
|
||||
|
||||
[[nodiscard]] int getHashSize() const { return hashSize; };
|
||||
|
||||
bool isEmpty() const { return count == 0; };
|
||||
|
||||
bool isFull() const { return count == hashSize; };
|
||||
|
||||
double getLoadFactor() const { throw std::logic_error("Not implemented: HashTable.getLoadFactor()"); };
|
||||
|
||||
bool insert(const T &item, int h(const T&, int)) { throw std::logic_error("Not implemented: HashTable.insert()"); };
|
||||
|
||||
bool remove(const T &item, int h(const T&), int) { throw std::logic_error("Not implemented: HashTable.remove()"); };
|
||||
|
||||
bool search(const T &item, int h(const T&), int) { throw std::logic_error("Not implemented: HashTable.search()"); };
|
||||
|
||||
int getTotalCollisions() const { throw std::logic_error("Not implemented: HashTable.getTotalCollisions()"); };
|
||||
|
||||
int getMaxCollisions() const { throw std::logic_error("Not implemented: HashTable.getMaxCollisions()"); };
|
||||
};
|
||||
|
||||
#endif //INC_08_TEAM_PROJECT_HASHTABLE_H
|
29
Stack.h
Normal file
29
Stack.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef INC_08_TEAM_PROJECT_STACK_H
|
||||
#define INC_08_TEAM_PROJECT_STACK_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include "StackNode.h"
|
||||
|
||||
template<typename T>
|
||||
class Stack {
|
||||
private:
|
||||
StackNode<T> *top;
|
||||
int count;
|
||||
|
||||
public:
|
||||
Stack() : top(nullptr), count(0) {};
|
||||
|
||||
~Stack() { throw std::logic_error("Not implemented: ~Stack()"); };
|
||||
|
||||
[[nodiscard]] bool isEmpty() const { return count == 0; };
|
||||
|
||||
[[nodiscard]] int getCount() const { return count; };
|
||||
|
||||
void push(const T &data) { throw std::logic_error("Not implemented: Stack.push()"); };
|
||||
|
||||
T pop() { throw std::logic_error("Not implemented: Stack.pop()"); };
|
||||
|
||||
T peek() { throw std::logic_error("Not implemented: Stack.peek()"); };
|
||||
};
|
||||
|
||||
#endif //INC_08_TEAM_PROJECT_STACK_H
|
1
StackNode.cpp
Normal file
1
StackNode.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "StackNode.h"
|
10
StackNode.h
Normal file
10
StackNode.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef INC_08_TEAM_PROJECT_STACKNODE_H
|
||||
#define INC_08_TEAM_PROJECT_STACKNODE_H
|
||||
|
||||
template<typename T>
|
||||
class StackNode {
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //INC_08_TEAM_PROJECT_STACKNODE_H
|
164
main.cpp
Normal file
164
main.cpp
Normal file
@ -0,0 +1,164 @@
|
||||
// # Project Requirements
|
||||
//
|
||||
// Begin by displaying some general information about the project, the names and tasks of the developers.
|
||||
// Processing is to be menu-driven with the following options:
|
||||
//
|
||||
// - Add a new data item.
|
||||
// - Add data from an input file (get the name of the input file from the user). (does it overwrite?)
|
||||
// - Delete data (one item).
|
||||
// - Find and display one element using the primary key.
|
||||
// - List data sorted by the primary key.
|
||||
// - Hidden print option (do not show it in the menu: details are given in Team Project- Part2).
|
||||
// - display the indented tree
|
||||
// - Write data to a file.
|
||||
// - Statistics (details are given in Team Project-Part2)
|
||||
// - load factor
|
||||
// - number of collisions (total)
|
||||
// - longest collision path
|
||||
// - Hidden option (do not show it in the menu): when selected, display the names of the team members.
|
||||
// - Help – to show the menu. Show the menu once, before the loop, then show the menu upon request: “Enter an option (H – for help): ”
|
||||
// - Exit
|
||||
//
|
||||
// At the end of the program, the data are to be automatically written to a file.
|
||||
// This is in addition to the menu write file option.
|
||||
// The output file name does not have to be the same as the input file name,
|
||||
// but the file format must be the same so that it can be read back into the program.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "utils.h"
|
||||
#include "CPU.h"
|
||||
#include "HashTable.h"
|
||||
#include "BinarySearchTree.h"
|
||||
#include "Stack.h"
|
||||
|
||||
using std::cin, std::cout, std::string, std::vector;
|
||||
|
||||
void printHelp() {
|
||||
static const vector<int> helpWidths = {5, 40};
|
||||
static const vector<vector<string>> helpData = {
|
||||
{"Key", "Command"},
|
||||
{"H", "Help"},
|
||||
{"I", "Insert a new record"},
|
||||
{"F", "File input: add data from a file"},
|
||||
{"D", "Delete one record"},
|
||||
{"U", "Undo delete"},
|
||||
{"L", "List all CPUs sorted by primary key"},
|
||||
{"S", "Search for a CPU by the primary key"},
|
||||
{"W", "Write data to a file"},
|
||||
{"T", "Hashtable statistics"},
|
||||
{"Q", "Quit"},
|
||||
{"P", "Hidden print option (do not show it in the menu: print indented tree)"},
|
||||
{"Z", "Hidden option (do not show it in the menu: display names of team members)"},
|
||||
};
|
||||
printTable(helpWidths, helpData);
|
||||
}
|
||||
|
||||
void printTeam() {
|
||||
static const vector<int> teamWidths = {40};
|
||||
static const vector<vector<string>> teamData = {
|
||||
{"Team Members"},
|
||||
{"Kevin Cremin"},
|
||||
{"Kevin Galvan Serrano"},
|
||||
{"Joshiro Lawrence"},
|
||||
{"Tuhin Mondal"},
|
||||
{"Iurii Tatishchev"},
|
||||
};
|
||||
printTable(teamWidths, teamData);
|
||||
}
|
||||
|
||||
void processInput(char command, HashTable<CPU>& table, BinarySearchTree<CPU>& tree, Stack<CPU>& stack);
|
||||
|
||||
CPU readCPUInfo();
|
||||
|
||||
int main() {
|
||||
// Print help table for commands
|
||||
printHelp();
|
||||
|
||||
HashTable<CPU> cpuTable;
|
||||
BinarySearchTree<CPU> cpuTree;
|
||||
Stack<CPU> undoStack;
|
||||
|
||||
char command = ' ';
|
||||
while (command != 'Q') {
|
||||
cout << "Enter an option (H - for help): ";
|
||||
cin >> command;
|
||||
// Temporary try catch block to handle unimplemented commands
|
||||
try {
|
||||
processInput(toupper(command, std::locale()), cpuTable, cpuTree, undoStack);
|
||||
} catch (std::logic_error& e) {
|
||||
cout << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
// Quit command received
|
||||
// TODO: Write data to a file
|
||||
cout << "Exiting program...\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void insertCPU(HashTable<CPU> &hashTable, BinarySearchTree<CPU> &tree);
|
||||
|
||||
void processInput(char command, HashTable<CPU> &cpuTable, BinarySearchTree<CPU> &cpuTree, Stack<CPU> &undoStack) {
|
||||
switch (command) {
|
||||
case 'H':
|
||||
printHelp();
|
||||
break;
|
||||
case 'I': // Insert a new record
|
||||
insertCPU(cpuTable, cpuTree);
|
||||
break;
|
||||
case 'F': // File input: add data from a file
|
||||
throw std::logic_error("Not yet implemented: File input: add data from a file");
|
||||
break;
|
||||
case 'D': // Delete one record
|
||||
throw std::logic_error("Not yet implemented: Delete one record");
|
||||
break;
|
||||
case 'U': // Undo delete
|
||||
throw std::logic_error("Not yet implemented: Undo delete");
|
||||
break;
|
||||
case 'L': // List all CPUs sorted by primary key
|
||||
throw std::logic_error("Not yet implemented: List all CPUs sorted by primary key");
|
||||
break;
|
||||
case 'S': // Search for a CPU by the primary key
|
||||
throw std::logic_error("Not yet implemented: Search for a CPU by the primary key");
|
||||
break;
|
||||
case 'W': // Write data to a file
|
||||
throw std::logic_error("Not yet implemented: Write data to a file");
|
||||
break;
|
||||
case 'T': // Hashtable statistics
|
||||
throw std::logic_error("Not yet implemented: Hashtable statistics");
|
||||
break;
|
||||
case 'P': // Print indented tree
|
||||
throw std::logic_error("Not yet implemented: Print indented tree");
|
||||
break;
|
||||
case 'Z': // Display names of team members
|
||||
printTeam();
|
||||
break;
|
||||
case 'Q': // Quit
|
||||
break;
|
||||
default:
|
||||
cout << "Invalid command. Press 'H' to view available commands.\n";
|
||||
}
|
||||
}
|
||||
|
||||
void insertCPU(HashTable<CPU> &hashTable, BinarySearchTree<CPU> &tree) {
|
||||
string cpuId;
|
||||
int releaseYear, coreCount;
|
||||
string architecture;
|
||||
double baseClock;
|
||||
cout << "Enter CPU ID: ";
|
||||
cin >> cpuId;
|
||||
cout << "Enter release year: ";
|
||||
cin >> releaseYear;
|
||||
cout << "Enter core count: ";
|
||||
cin >> coreCount;
|
||||
cout << "Enter architecture: ";
|
||||
cin >> architecture;
|
||||
cout << "Enter base clock: ";
|
||||
cin >> baseClock;
|
||||
CPU cpu(cpuId, releaseYear, coreCount, architecture, baseClock);
|
||||
|
||||
hashTable.insert(cpu, key_to_index);
|
||||
tree.insert(cpu);
|
||||
}
|
71
utils.cpp
Normal file
71
utils.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#include <iostream>
|
||||
#include "utils.h"
|
||||
using std::cout;
|
||||
|
||||
void printRow(const vector<int> &widths, const vector<string>& row) {
|
||||
cout << '|';
|
||||
for (int i = 0; i < widths.size(); i++) {
|
||||
cout << ' ';
|
||||
cout.width(widths[i] - 1);
|
||||
cout << std::left << row[i];
|
||||
cout << '|';
|
||||
}
|
||||
cout << '\n';
|
||||
};
|
||||
|
||||
/*
|
||||
* Print ascii/unicode table with given column widths and data. For example:
|
||||
* ┌────────────────────────────────────────┬──────────┬────────────────────────┬────────────────┐
|
||||
* | Col1 | Col2 | Col3 | Numeric Column |
|
||||
* +========================================+==========+========================+================+
|
||||
* | Value 1 | Value 2 | 123 | 10.0 |
|
||||
* | Separate | cols | with a tab or 4 spaces | -2,027.1 |
|
||||
* | This is a row with only one cell | | | |
|
||||
* └────────────────────────────────────────┴──────────┴────────────────────────┴────────────────┘
|
||||
*/
|
||||
void printTable(const vector<int>& widths, const vector<vector<string>>& data) {
|
||||
// Print top border
|
||||
cout << "┌";
|
||||
for (int width : widths) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
cout << "─";
|
||||
}
|
||||
cout << "┬";
|
||||
}
|
||||
cout << "\b┐\n";
|
||||
|
||||
// Print header
|
||||
cout << '|';
|
||||
for (int i = 0; i < widths.size(); i++) {
|
||||
cout << ' ';
|
||||
cout.width(widths[i] - 1);
|
||||
cout << std::left << data[0][i];
|
||||
cout << '|';
|
||||
}
|
||||
cout << '\n';
|
||||
|
||||
// Print middle border
|
||||
cout << '+';
|
||||
for (int width : widths) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
cout << '=';
|
||||
}
|
||||
cout << '+';
|
||||
}
|
||||
cout << '\n';
|
||||
|
||||
// Print data
|
||||
for (int i = 1; i < data.size(); i++) {
|
||||
printRow(widths, data[i]);
|
||||
}
|
||||
|
||||
// Print bottom border
|
||||
cout << "└";
|
||||
for (int width : widths) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
cout << "─";
|
||||
}
|
||||
cout << "┴";
|
||||
}
|
||||
cout << "\b┘\n";
|
||||
}
|
12
utils.h
Normal file
12
utils.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef INC_08_TEAM_PROJECT_UTILS_H
|
||||
#define INC_08_TEAM_PROJECT_UTILS_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
using std::vector, std::string;
|
||||
|
||||
void printRow(const vector<int> &widths, const vector<string>& row);
|
||||
|
||||
void printTable(const vector<int>& widths, const vector<vector<string>>& data);
|
||||
|
||||
#endif //INC_08_TEAM_PROJECT_UTILS_H
|
Loading…
x
Reference in New Issue
Block a user