Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: Joshua Simard
- Date: 4/6/2020
- Assignment: EH5
- Description: Using a one-dimensional array. Read in 20 numbers, each of which is between 10 and 100 inclusive.
- As each number is read, validate it and store it in the array only if it is not a duplicate of a number
- already read in. After reading all the values, display only the unique values that the user entered,
- Test case MUST include cases were all values are different, none are different, and a couple of cases
- where there are several duplicates. You should create several files of data, and then read them in as your test cases.
- Notes: This program writes in 5 files at once.
- */
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main() {
- int const SIZE = 20;
- int const CASE_NUM = 5;
- int arr[21];
- int counter = 1;
- for (int g = CASE_NUM; g >= 0; g--) {
- string fileName = "file";
- fileName += to_string(g);
- fileName += ".txt";
- cout << fileName << endl;
- ifstream readIn(fileName);
- for (int i = SIZE; i >= 1; i--) {
- int temp;
- readIn >> temp;
- for (int v = counter; v >= 0; v--) {
- if (temp == arr[v]) {
- temp = 101;
- }
- }
- if (temp >= 10 && temp <= 100) {
- arr[i] = temp;
- }
- else {
- arr[i] = 0;
- }
- counter++;
- }
- for (int i = SIZE; i >= 1; i--) {
- if (arr[i] != 0) {
- cout << arr[i] << " :Index: " << i << endl;
- }
- }
- cout << endl << "------------------------------" << endl << endl;
- }
- system("pause");
- }
- /*
- In File 5, there is one duplicate. In file 4, all the values are 92.
- In files 3, 2, and 1, several items are duplicates.
- In file 0, no items are duplicates.
- Results:
- file5.txt
- 56 :Index: 20
- 24 :Index: 19
- 65 :Index: 17
- 25 :Index: 16
- 25 :Index: 15
- 12 :Index: 14
- 82 :Index: 13
- 23 :Index: 12
- 15 :Index: 11
- 85 :Index: 10
- 95 :Index: 9
- 45 :Index: 8
- 36 :Index: 7
- 24 :Index: 6
- 72 :Index: 5
- 32 :Index: 3
- 62 :Index: 2
- ------------------------------
- file4.txt
- 92 :Index: 20
- ------------------------------
- file3.txt
- 81 :Index: 20
- 74 :Index: 19
- 12 :Index: 18
- 55 :Index: 17
- 46 :Index: 16
- 27 :Index: 15
- 44 :Index: 14
- 21 :Index: 13
- 28 :Index: 12
- 99 :Index: 11
- 86 :Index: 10
- 84 :Index: 7
- 78 :Index: 6
- 90 :Index: 5
- 100 :Index: 3
- 82 :Index: 2
- 63 :Index: 1
- ------------------------------
- file2.txt
- 56 :Index: 20
- 64 :Index: 18
- 36 :Index: 17
- 30 :Index: 15
- 40 :Index: 13
- 69 :Index: 9
- 54 :Index: 7
- 49 :Index: 6
- 21 :Index: 4
- 88 :Index: 1
- ------------------------------
- file1.txt
- 99 :Index: 20
- 59 :Index: 19
- 61 :Index: 18
- 71 :Index: 17
- 80 :Index: 16
- 25 :Index: 15
- 46 :Index: 14
- 23 :Index: 13
- 15 :Index: 12
- 96 :Index: 9
- 64 :Index: 8
- 73 :Index: 7
- 51 :Index: 6
- 57 :Index: 5
- 54 :Index: 4
- 18 :Index: 3
- 14 :Index: 2
- 28 :Index: 1
- ------------------------------
- file0.txt
- 88 :Index: 20
- 38 :Index: 18
- 49 :Index: 17
- 36 :Index: 16
- 100 :Index: 15
- 77 :Index: 14
- 32 :Index: 13
- 83 :Index: 12
- 94 :Index: 11
- 46 :Index: 10
- 33 :Index: 9
- 45 :Index: 8
- 55 :Index: 7
- 53 :Index: 6
- 90 :Index: 4
- 52 :Index: 3
- 81 :Index: 2
- 50 :Index: 1
- ------------------------------
- Press any key to continue . . .
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement