diff options
| author | tylr <[email protected]> | 2021-12-03 13:13:40 -0800 |
|---|---|---|
| committer | tylr <[email protected]> | 2021-12-03 13:13:40 -0800 |
| commit | 9da1a7eca65aa4810f7cddf7bff1724ccca1a571 (patch) | |
| tree | 8604a04048b2e3f747913ea904af15466dbb3dc5 | |
| parent | Complete. (diff) | |
| download | cst116-lab9-till-t-9da1a7eca65aa4810f7cddf7bff1724ccca1a571.tar.xz cst116-lab9-till-t-9da1a7eca65aa4810f7cddf7bff1724ccca1a571.zip | |
Complete number 3.
| -rw-r--r-- | lab9/lab9.xcodeproj/project.pbxproj | 284 | ||||
| -rw-r--r-- | lab9/lab9.xcodeproj/project.xcworkspace/contents.xcworkspacedata | 7 | ||||
| -rw-r--r-- | lab9/lab9.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist | 8 | ||||
| -rw-r--r-- | lab9/lab9.xcodeproj/project.xcworkspace/xcuserdata/tylertaormina.xcuserdatad/UserInterfaceState.xcuserstate | bin | 16717 -> 0 bytes | |||
| -rw-r--r-- | lab9/lab9.xcodeproj/xcuserdata/tylertaormina.xcuserdatad/xcschemes/xcschememanagement.plist | 14 | ||||
| -rw-r--r-- | lab9/lab9/data.txt | 10 | ||||
| -rw-r--r-- | lab9/lab9/main.cpp | 115 | ||||
| -rw-r--r-- | num2/num2.cpp | 6 | ||||
| -rwxr-xr-x | num3/a.out | bin | 0 -> 75986 bytes | |||
| -rw-r--r-- | num3/data.txt | 6 | ||||
| -rw-r--r-- | num3/data2.txt | 4 | ||||
| -rw-r--r-- | num3/hello.txt | 5 | ||||
| -rw-r--r-- | num3/num3.cpp | 143 |
13 files changed, 164 insertions, 438 deletions
diff --git a/lab9/lab9.xcodeproj/project.pbxproj b/lab9/lab9.xcodeproj/project.pbxproj deleted file mode 100644 index 1d19a18..0000000 --- a/lab9/lab9.xcodeproj/project.pbxproj +++ /dev/null @@ -1,284 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 55; - objects = { - -/* Begin PBXBuildFile section */ - 4F6E708B2758AF5D00A8F399 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4F6E708A2758AF5D00A8F399 /* main.cpp */; }; -/* End PBXBuildFile section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 4F6E70852758AF5D00A8F399 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = /usr/share/man/man1/; - dstSubfolderSpec = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 1; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 4F6E70872758AF5D00A8F399 /* lab9 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = lab9; sourceTree = BUILT_PRODUCTS_DIR; }; - 4F6E708A2758AF5D00A8F399 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; }; - 4F6E70912758AF7300A8F399 /* num2 */ = {isa = PBXFileReference; lastKnownFileType = folder; name = num2; path = ../num2; sourceTree = "<group>"; }; - 4F6E70922758AFE500A8F399 /* data.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = data.txt; sourceTree = "<group>"; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 4F6E70842758AF5D00A8F399 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 4F6E707E2758AF5D00A8F399 = { - isa = PBXGroup; - children = ( - 4F6E70912758AF7300A8F399 /* num2 */, - 4F6E70892758AF5D00A8F399 /* lab9 */, - 4F6E70882758AF5D00A8F399 /* Products */, - ); - sourceTree = "<group>"; - }; - 4F6E70882758AF5D00A8F399 /* Products */ = { - isa = PBXGroup; - children = ( - 4F6E70872758AF5D00A8F399 /* lab9 */, - ); - name = Products; - sourceTree = "<group>"; - }; - 4F6E70892758AF5D00A8F399 /* lab9 */ = { - isa = PBXGroup; - children = ( - 4F6E708A2758AF5D00A8F399 /* main.cpp */, - 4F6E70922758AFE500A8F399 /* data.txt */, - ); - path = lab9; - sourceTree = "<group>"; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 4F6E70862758AF5D00A8F399 /* lab9 */ = { - isa = PBXNativeTarget; - buildConfigurationList = 4F6E708E2758AF5D00A8F399 /* Build configuration list for PBXNativeTarget "lab9" */; - buildPhases = ( - 4F6E70832758AF5D00A8F399 /* Sources */, - 4F6E70842758AF5D00A8F399 /* Frameworks */, - 4F6E70852758AF5D00A8F399 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = lab9; - productName = lab9; - productReference = 4F6E70872758AF5D00A8F399 /* lab9 */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 4F6E707F2758AF5D00A8F399 /* Project object */ = { - isa = PBXProject; - attributes = { - BuildIndependentTargetsInParallel = 1; - LastUpgradeCheck = 1310; - TargetAttributes = { - 4F6E70862758AF5D00A8F399 = { - CreatedOnToolsVersion = 13.1; - }; - }; - }; - buildConfigurationList = 4F6E70822758AF5D00A8F399 /* Build configuration list for PBXProject "lab9" */; - compatibilityVersion = "Xcode 13.0"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 4F6E707E2758AF5D00A8F399; - productRefGroup = 4F6E70882758AF5D00A8F399 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 4F6E70862758AF5D00A8F399 /* lab9 */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 4F6E70832758AF5D00A8F399 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 4F6E708B2758AF5D00A8F399 /* main.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 4F6E708C2758AF5D00A8F399 /* 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_CXX_LIBRARY = "libc++"; - 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.0; - MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; - MTL_FAST_MATH = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - }; - name = Debug; - }; - 4F6E708D2758AF5D00A8F399 /* 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_CXX_LIBRARY = "libc++"; - 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.0; - MTL_ENABLE_DEBUG_INFO = NO; - MTL_FAST_MATH = YES; - SDKROOT = macosx; - }; - name = Release; - }; - 4F6E708F2758AF5D00A8F399 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 4F6E70902758AF5D00A8F399 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 4F6E70822758AF5D00A8F399 /* Build configuration list for PBXProject "lab9" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 4F6E708C2758AF5D00A8F399 /* Debug */, - 4F6E708D2758AF5D00A8F399 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 4F6E708E2758AF5D00A8F399 /* Build configuration list for PBXNativeTarget "lab9" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 4F6E708F2758AF5D00A8F399 /* Debug */, - 4F6E70902758AF5D00A8F399 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 4F6E707F2758AF5D00A8F399 /* Project object */; -} diff --git a/lab9/lab9.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/lab9/lab9.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a..0000000 --- a/lab9/lab9.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<Workspace - version = "1.0"> - <FileRef - location = "self:"> - </FileRef> -</Workspace> diff --git a/lab9/lab9.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/lab9/lab9.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/lab9/lab9.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ -<?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> diff --git a/lab9/lab9.xcodeproj/project.xcworkspace/xcuserdata/tylertaormina.xcuserdatad/UserInterfaceState.xcuserstate b/lab9/lab9.xcodeproj/project.xcworkspace/xcuserdata/tylertaormina.xcuserdatad/UserInterfaceState.xcuserstate Binary files differdeleted file mode 100644 index 678e2fb..0000000 --- a/lab9/lab9.xcodeproj/project.xcworkspace/xcuserdata/tylertaormina.xcuserdatad/UserInterfaceState.xcuserstate +++ /dev/null diff --git a/lab9/lab9.xcodeproj/xcuserdata/tylertaormina.xcuserdatad/xcschemes/xcschememanagement.plist b/lab9/lab9.xcodeproj/xcuserdata/tylertaormina.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index d2e1464..0000000 --- a/lab9/lab9.xcodeproj/xcuserdata/tylertaormina.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,14 +0,0 @@ -<?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>lab9.xcscheme_^#shared#^_</key> - <dict> - <key>orderHint</key> - <integer>0</integer> - </dict> - </dict> -</dict> -</plist> diff --git a/lab9/lab9/data.txt b/lab9/lab9/data.txt deleted file mode 100644 index d28c343..0000000 --- a/lab9/lab9/data.txt +++ /dev/null @@ -1,10 +0,0 @@ -120 -234 -33 -2021 -44 -23 -530 -567 -340 -501 diff --git a/lab9/lab9/main.cpp b/lab9/lab9/main.cpp deleted file mode 100644 index e6bcc54..0000000 --- a/lab9/lab9/main.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include <iostream> -#include <fstream> // For the files!!!! -#include <iomanip> // For manipulators & formatting options -#include <stdio.h> - -using std::cin; -using std::cout; -using std::endl; -using std::setw; -using std::ios; -using std::resetiosflags; -using std::setiosflags; - -using std::ifstream; -using std::ofstream; -const int MAX = 10; - -int ReadData ( ifstream &inFile, int data_arr[]); -void Sort (int data_arr[], int counter); -void Display_LS(int data_arr[], int counter); - - -int main() -{ - int i; - int record_counter = 0; - int data[MAX]; - - ifstream inFile; - - // Notice how this automatically opens the file - - inFile.open ( "data.txt"); - - if ( inFile.is_open ( ) ) - { - - record_counter = ReadData (inFile, data); - inFile.close ( ); - } - - else - { - cout << "Trouble Opening File: inFile"; - cout << "\n\n\t\t ** About to EXIT NOW! ** "; - } - - Display_LS(data, record_counter); - - Sort(data, record_counter); - - for (i = 0; i < record_counter; i++) - cout << data[i] << endl; - - return 0; - -} - - -int ReadData(ifstream &inFile, int data_arr[]) -{ - int counter = 0; - inFile >> data_arr[counter]; // Priming Read - - while ( !inFile.eof ( ) ) - { - counter++; - inFile >> data_arr[counter] ; - } - - return counter; -} - - -void Sort (int data_arr[], int counter) -{ - int i; - int j; - int temp; - - for (i = 0; i < counter; i++) - { - for (j = i+1; j < counter; j++) - { - if (data_arr[i] > data_arr[j]) - { - temp = data_arr[i]; - data_arr[i] = data_arr[j]; - data_arr[j] = temp; - } - } - } -} - - -void Display_LS(int data_arr[], int counter) -{ - int large, small; - int i; - small = data_arr[0]; - large = data_arr[0]; - for (i = 1; i < counter; i++) - { - if (small > data_arr[i]) - small = data_arr[i]; - if (large < data_arr[i]) - large = data_arr[i]; - - } - - cout << "The smallest number is: " << small << endl; - cout << "The largest number is: " << large << endl; - -} - diff --git a/num2/num2.cpp b/num2/num2.cpp index 18f17bf..274acac 100644 --- a/num2/num2.cpp +++ b/num2/num2.cpp @@ -1,3 +1,9 @@ +//Tylr Taormina +//CST 116 +//Dec 3, 2021 + + + #include <iostream> #include <fstream> // For the files!!!! #include <iomanip> // For manipulators & formatting options diff --git a/num3/a.out b/num3/a.out Binary files differnew file mode 100755 index 0000000..103db5f --- /dev/null +++ b/num3/a.out diff --git a/num3/data.txt b/num3/data.txt new file mode 100644 index 0000000..46d17ed --- /dev/null +++ b/num3/data.txt @@ -0,0 +1,6 @@ +Hello world. +Semester is almost over. +What's for dinner. +How many lines should we do. +Thats enough. +Now write the code. diff --git a/num3/data2.txt b/num3/data2.txt new file mode 100644 index 0000000..6f9989e --- /dev/null +++ b/num3/data2.txt @@ -0,0 +1,4 @@ +This file was built by Tylr + +We included one blank line here? +Lets see if this works! diff --git a/num3/hello.txt b/num3/hello.txt new file mode 100644 index 0000000..3870db1 --- /dev/null +++ b/num3/hello.txt @@ -0,0 +1,5 @@ +Hello! +Everything must end in a period for this to work. +No period +Let's see + diff --git a/num3/num3.cpp b/num3/num3.cpp new file mode 100644 index 0000000..d3ea934 --- /dev/null +++ b/num3/num3.cpp @@ -0,0 +1,143 @@ +//Tylr Taormina +//CST 116 +//Dec 3, 2021 + + + +#include <iostream> +#include <fstream> +#include <stdio.h> +#include <string> +#include <algorithm> + +using std::cin; +using std::cout; +using std::endl; +using std::ifstream; +using std::ofstream; +const int MAX = 10; + +int ReadData (ifstream &inFile, std::string data_arr[MAX]); +void CharCount (std::string data_arr[MAX], int length_arr[MAX], int charCount_arr[MAX]); +void FindLength(std::string data_arr[MAX], int length_arr[MAX]); + + +int main() +{ + //stand alone objects + std::string input; + int flag; + int i; + int record_counter = 0; + + //arrays + std::string data[MAX]; + int length_arr[MAX]; + int charCount_arr[MAX]; + + + //display the file choices + cout << "THE FILES WE HAVE TO CHOOSE FROM: " << endl; + cout << "===================================================" << endl; + cout << "data.txt" << endl; + cout << "data2.txt" << endl; + cout << "hello.txt\n\n" << endl; + + + cout << "Please enter a name for the file to open: "; + cin >> input; + + //modify input to avoid case sensitivity errors + transform(input.begin(), input.end(), input.begin(), ::tolower); + + ifstream inFile; + inFile.open (input); + + if ( inFile.is_open ( ) ) + { + + record_counter = ReadData (inFile, data); + inFile.close ( ); + flag = 1; + } + + else + { + cout << "Trouble Opening File: " << input << endl; + cout << "Check to make sure your spelling is correct for the file you are trying to open. Include .txt or whatever file extension is relevant." << endl; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + flag = 0; + } + + //Builds arrays. See functions below for descriptions. + FindLength(data, length_arr); + CharCount(data, length_arr, charCount_arr); + + // the flag helps to only display info if we can open the file. + if (flag == 1) + { + for (i = 0; i < record_counter; i++) + { + cout << i+1 << ") " << data[i] << " (" << charCount_arr[i] << " characters not counting spaces)" << endl; + + } + } + return 0; + +} + + +int ReadData(ifstream &inFile, std::string data_arr[MAX]) + //Reads data into an array of strings using new lines + //as the indicator to end the array. +{ + int counter = 0; + + getline(inFile, data_arr[0],'\n'); + + while ( !inFile.eof ( ) ) + { + counter++; + getline(inFile, data_arr[counter], '\n'); + } + + return counter; +} + + +void FindLength(std::string data_arr[MAX], int length_arr[]) + //Finds the length of each string in the array + //counting the number of spaces. This helps + //keep us within the scope of our array when + //counting characters in the CharCount function. +{ + int i; + + for (i = 0; i < MAX; i++) + { + length_arr[i] = data_arr[i].size(); + } + +} + + +void CharCount (std::string data_arr[MAX], int length_arr[], int charCount_arr[MAX]) + //Counts the number of characters not including spaces. If we wanted + //to include spaces, we could simply use the length array that is + //built in the FindLength function. +{ + int ctr = 0; + int i, j; + + for (i = 0; i < MAX; i++) + { + for (j = 0; j < length_arr[i]; j++) + { + if (data_arr[i][j] != ' ') + ctr++; + } + charCount_arr[i] = ctr; + ctr = 0; + } +} + |