-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDS_1.cpp
More file actions
111 lines (89 loc) · 2.97 KB
/
Copy pathDS_1.cpp
File metadata and controls
111 lines (89 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// DS_1.cpp: This file contains the implementation of functions declared in DS_1.h
#include <iostream>
#include <fstream>
#include <array>
#include "DS_1.h"
#include <string>
using namespace std;
void readingFile(const string& filename, int size, int* array) {
// ... Your existing code ...
//MODIFY TO USE THE ARRAY THAT IS BEING PASSED INTO THE FUNCTION
string inFileName = filename + ".txt";
ifstream inFile;
inFile.open(inFileName.c_str());
if (inFile.is_open())
{
for (int i = 0; i < size; i++)
{
inFile >> array[i];
cout << array[i] << " ";
}
inFile.close(); // CLose input file
}
else { //Error message
cerr << "Can't find input file " << inFileName << endl;
}
}
void replaceValue(int* array) {
// ... Your existing code ...
int userInput;
cout << "\nEnter the Integer you would like to add to your bag." << endl;
cin >> userInput;
}
void find(int* array) {
// ... Your existing code ...
int integer = 0;
cout << "Enter in the unique integer you would like to find in the array" << endl;
cin >> integer;
//loops through the array to find the index of a specific integer
for (int i = 0; i < 100; i++) {
if (array[i] == integer) {
cout << "The integer " << integer << " is present at index " << i << endl;
return i;
}
}
}
void modifyInteger(int* array, int index) {
// ... Your existing code ...
int integer=0;
if (integer == 0) {
try {
cout << "Enter in the unique integer you would like to find in the array" << endl;
cin >> integer;
if (isdigit(integer)) {
}
else {
throw std::invalid_argument("please only enter integers - rerun program");
}
}
catch (std::invalid_argument& e) {
cout << "Caught exception please only enter integers - rerun program";
}
catch (...) {
cout << "Caught exception please rerun program";
}
}else {
// take integer index and bring it back to the user
}
}
void addToArray(int* array) {
// ... Your existing code ...
//ask
int userInput;
//try catch user input make sure its a number
cout << "\nEnter the Integer you would like to delete all instances of from your bag." << endl;
cin >> userInput;
cout << "Deleting all instances of the chosen integer from your bag..." << endl;
}
void showMenu() {
//r for replace
//f for find
//m for modify
//a for add
cout << "\n***Choose an option from the menu!***" << endl;
cout << "\nR - Replace a value in the array with either 0 or remove the integer altogether" << endl;
cout << "F - Check if a certain integer exists in the array" << endl;
cout << "M - Modify the value of an integer in the array" << endl;
cout << "A - Add a new integer to the end of the array" << endl;
cout << "X - Finish" << endl;
}