added old projects
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,290 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 55;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
D94331272863F06C00914B9F /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D94331262863F06C00914B9F /* main.cpp */; };
|
||||
D943312F2863F3E000914B9F /* list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D943312D2863F3DF00914B9F /* list.cpp */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
D94331212863F06C00914B9F /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = /usr/share/man/man1/;
|
||||
dstSubfolderSpec = 0;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
D94331232863F06C00914B9F /* BookList */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BookList; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D94331262863F06C00914B9F /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
|
||||
D943312D2863F3DF00914B9F /* list.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = list.cpp; sourceTree = "<group>"; };
|
||||
D9EA3E02286B6984004F363F /* input.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input.h; sourceTree = "<group>"; };
|
||||
D9EA3E03286B6B52004F363F /* list.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
D94331202863F06C00914B9F /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
D943311A2863F06C00914B9F = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D94331252863F06C00914B9F /* BookList */,
|
||||
D94331242863F06C00914B9F /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D94331242863F06C00914B9F /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D94331232863F06C00914B9F /* BookList */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D94331252863F06C00914B9F /* BookList */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D9EA3E03286B6B52004F363F /* list.h */,
|
||||
D9EA3E02286B6984004F363F /* input.h */,
|
||||
D94331262863F06C00914B9F /* main.cpp */,
|
||||
D943312D2863F3DF00914B9F /* list.cpp */,
|
||||
);
|
||||
path = BookList;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
D94331222863F06C00914B9F /* BookList */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = D943312A2863F06C00914B9F /* Build configuration list for PBXNativeTarget "BookList" */;
|
||||
buildPhases = (
|
||||
D943311F2863F06C00914B9F /* Sources */,
|
||||
D94331202863F06C00914B9F /* Frameworks */,
|
||||
D94331212863F06C00914B9F /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = BookList;
|
||||
productName = BookList;
|
||||
productReference = D94331232863F06C00914B9F /* BookList */;
|
||||
productType = "com.apple.product-type.tool";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
D943311B2863F06C00914B9F /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastUpgradeCheck = 1340;
|
||||
TargetAttributes = {
|
||||
D94331222863F06C00914B9F = {
|
||||
CreatedOnToolsVersion = 13.4.1;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = D943311E2863F06C00914B9F /* Build configuration list for PBXProject "BookList" */;
|
||||
compatibilityVersion = "Xcode 13.0";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = D943311A2863F06C00914B9F;
|
||||
productRefGroup = D94331242863F06C00914B9F /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
D94331222863F06C00914B9F /* BookList */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
D943311F2863F06C00914B9F /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D94331272863F06C00914B9F /* main.cpp in Sources */,
|
||||
D943312F2863F3E000914B9F /* list.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
D94331282863F06C00914B9F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 12.3;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
D94331292863F06C00914B9F /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 12.3;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
D943312B2863F06C00914B9F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = N3GD25M5J3;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
D943312C2863F06C00914B9F /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = N3GD25M5J3;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
D943311E2863F06C00914B9F /* Build configuration list for PBXProject "BookList" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
D94331282863F06C00914B9F /* Debug */,
|
||||
D94331292863F06C00914B9F /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
D943312A2863F06C00914B9F /* Build configuration list for PBXNativeTarget "BookList" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
D943312B2863F06C00914B9F /* Debug */,
|
||||
D943312C2863F06C00914B9F /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = D943311B2863F06C00914B9F /* Project object */;
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
Binary file not shown.
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
uuid = "49A36F6E-754C-42B3-ACFC-B1A11B69FD22"
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
</Bucket>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>BookList.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: g++ build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <iostream>
|
||||
#include <climits>
|
||||
#include <string>
|
||||
|
||||
template<typename inputType>
|
||||
|
||||
inputType ReadValue(std::string prompt)
|
||||
{
|
||||
inputType returnValue;
|
||||
std::cout << prompt;
|
||||
std::cin >> returnValue;
|
||||
while (std::cin.fail()) {
|
||||
std::cout << "Error! Cannot read input.\n";
|
||||
std::cin.clear();
|
||||
std::cin.ignore(INT_MAX,'\n');
|
||||
std::cout << prompt;
|
||||
std::cin >> returnValue;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
template<typename inputType>
|
||||
inputType ReadValue(std::string prompt, inputType minValue)
|
||||
{
|
||||
inputType returnValue=0;
|
||||
returnValue=ReadValue<inputType>(prompt);
|
||||
while (returnValue < minValue) {
|
||||
std::cout << "Error! Value must be >= " << minValue << std::endl;
|
||||
returnValue=ReadValue<inputType>(prompt);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
template<typename inputType>
|
||||
inputType ReadValue(std::string prompt, inputType minValue, inputType maxValue)
|
||||
{
|
||||
inputType returnValue=0;
|
||||
returnValue=ReadValue<inputType>(prompt,minValue);
|
||||
while (returnValue > maxValue) {
|
||||
std::cout << "Error! Value must be <= " << maxValue << std::endl;
|
||||
returnValue=ReadValue<inputType>(prompt,minValue);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
#include "list.h"
|
||||
#include "input.h"
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
void List::Clear()
|
||||
{
|
||||
if (size > 0)
|
||||
{
|
||||
delete[] data;
|
||||
size = 0;
|
||||
data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string List::Display()
|
||||
{
|
||||
std::string result;
|
||||
if (size > 0)
|
||||
{
|
||||
std::cout << "List values:\n";
|
||||
for (std::string *ptr = data; ptr < data + size; ptr++)
|
||||
{
|
||||
result = result + *ptr + " ";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "List is empty.\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// There must be a function to allow the list size to be increased without losing data that has been previously stored in the list.
|
||||
void List::Resize(long numValues)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (numValues < 1 || numValues > MAX_SIZE)
|
||||
{
|
||||
throw "Error! Invalid list size specified.";
|
||||
}
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
Clear();
|
||||
data = new std::string[numValues];
|
||||
|
||||
if (data == nullptr)
|
||||
{
|
||||
throw "Error! Could not allocate memory for list.";
|
||||
}
|
||||
|
||||
size = numValues;
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = new std::string[size + numValues];
|
||||
|
||||
copy(data, data + size, temp);
|
||||
|
||||
Clear();
|
||||
data = new std::string[size + numValues];
|
||||
|
||||
std::string *tempPtr = temp;
|
||||
|
||||
for (std::string *ptr=data; ptr<data+size+numValues; ptr++) {
|
||||
*ptr= *tempPtr;
|
||||
}
|
||||
|
||||
size = numValues + size;
|
||||
|
||||
delete[] temp;
|
||||
}
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
throw "Error! Could not allocate memory for list.";
|
||||
}
|
||||
}
|
||||
|
||||
void List::SetValue(std::string value, long pos)
|
||||
{
|
||||
if (pos < 0 || pos >= size)
|
||||
{
|
||||
throw "Error! Invalid position in list specified.";
|
||||
}
|
||||
data[pos] = value;
|
||||
}
|
||||
|
||||
std::string List::GetValue(long pos)
|
||||
{
|
||||
if (pos < 0 || pos >= size)
|
||||
{
|
||||
throw "Error! Invalid position in list specified.";
|
||||
}
|
||||
return data[pos];
|
||||
}
|
||||
|
||||
void List::Remove(std::string value)
|
||||
{
|
||||
int index;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (data[i] == value)
|
||||
{
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = index; i < size; i++)
|
||||
data[i] = data[i + 1];
|
||||
}
|
||||
|
||||
void List::Add()
|
||||
{
|
||||
try {
|
||||
long x=ReadValue<long>("Number of values? ");
|
||||
Resize(x);
|
||||
if (size == 0) {
|
||||
for (std::string *ptr=data; ptr<data+size; ptr++) {
|
||||
*ptr=ReadValue<std::string>("Value? ");
|
||||
}
|
||||
} else {
|
||||
for (std::string *ptr=data; ptr<data+size+x; ptr++) {
|
||||
*ptr=ReadValue<std::string>("Value? ");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const char* s) {
|
||||
throw s;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, List &l)
|
||||
{
|
||||
out << l.Display();
|
||||
return out;
|
||||
}
|
||||
|
||||
List::List()
|
||||
{
|
||||
data = nullptr;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
List::~List()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
List::List(const List &x)
|
||||
{
|
||||
size = x.size;
|
||||
data = new std::string[size];
|
||||
for (long i = 0; i < x.size; i++)
|
||||
{
|
||||
data[i] = x.data[i];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef LIST_H
|
||||
#define LIST_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class List
|
||||
{
|
||||
private:
|
||||
|
||||
|
||||
std::string* temp;
|
||||
|
||||
public:
|
||||
std::string* data;
|
||||
long size;
|
||||
enum {MAX_SIZE=1000};
|
||||
|
||||
void Remove(std::string value);
|
||||
void Add();
|
||||
void Resize(long numValues);
|
||||
void Clear();
|
||||
void SetValue(std::string value, long pos);
|
||||
std::string GetValue(long pos);
|
||||
long GetSize();
|
||||
void Input(long newSize);
|
||||
std::string Display();
|
||||
|
||||
|
||||
List();
|
||||
List(const List& l);
|
||||
~List();
|
||||
};
|
||||
|
||||
#endif
|
||||
std::istream& operator>> (std::istream& in, List& l);
|
||||
std::ostream& operator<< (std::ostream& out, List& l);
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// main.cpp
|
||||
// BookList
|
||||
//
|
||||
// Created by Austin Bennett on 6/22/22.
|
||||
//
|
||||
|
||||
/*
|
||||
Create a C++ program that will keep a list of books. Your program must meet the following criteria:
|
||||
ø The program will provide the user with a menu to add names to the list, delete a name from the list (searching by title), display the list in it's entirety
|
||||
√ The list of books will be stored as a dynamically allocated array of strings. The strings can be either STL strings or C style strings
|
||||
√ The list must be stored in a class
|
||||
√ There must be an operator overload created for the stream extraction operator that will handle the output of the list
|
||||
√ You must provide a copy constructor for the class that will allow the programmer to set one class object equal to another
|
||||
√ There must be a function to allow the list size to be increased without losing data that has been previously stored in the list.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "list.h"
|
||||
#include "input.h"
|
||||
|
||||
// The program will provide the user with a menu to add names to the list, delete a name from the list (searching by title), display the list in it's entirety
|
||||
void menu(List books) {
|
||||
int choice;
|
||||
bool inProgram = true;
|
||||
while (inProgram != false){
|
||||
std::cout << "*******************************\n";
|
||||
std::cout << " 1 - Add Item.\n";
|
||||
std::cout << " 2 - Delete Item.\n";
|
||||
std::cout << " 3 - Display List.\n";
|
||||
std::cout << " 4 - Exit.\n";
|
||||
|
||||
choice = ReadValue<int>("Enter your choice and press return: ");
|
||||
|
||||
switch (choice) {
|
||||
case 1: // Add Item
|
||||
books.Add();
|
||||
break;
|
||||
case 2: // Delete Item
|
||||
books.Remove(ReadValue<std::string>("Enter Book to Remove: "));
|
||||
break;
|
||||
case 3: // Display List
|
||||
// There must be an operator overload created for the stream extraction operator that will handle the output of the list
|
||||
std::cout << books;
|
||||
break;
|
||||
case 4:
|
||||
std::cout << "End of Program.\n";
|
||||
inProgram = false;
|
||||
break;
|
||||
default:
|
||||
std::cout << "Not a Valid Choice. \n";
|
||||
std::cout << "Choose again.\n";
|
||||
std::cin >> choice;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
// The list must be stored in a class
|
||||
List books;
|
||||
|
||||
menu(books);
|
||||
|
||||
// You must provide a copy constructor for the class that will allow the programmer to set one class object equal to another
|
||||
List books2 = List(books);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user