Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Written by Karl Hou
- // Student ID: 1445202
- #include <iostream>
- #include <string>
- #include <cstdlib>
- #include "MyStaticArray.h"
- using namespace std;
- #include "MyStaticArray.h"
- int main() {
- string number; // Number they want to input
- string indexer; // Where they want to store the number
- Array<double, 100> nums; // 1st Array, for actual nums
- Array<int, 100> indexes; // 2nd Array, to keep track of ints
- int place = 0; // While loop counter for later
- cout << "\n\nWELCOME to the FANTASTICAL and FANTASIMICAL Array driver!"; //Intro
- // VALUE ENTERING LOOP
- while (true) //Infinite while loop with a break on Q. Array is only 100 long
- {
- //but oh well.
- cout << "\nAt what location will you put what? [Q in either to quit]: ";
- cin >> indexer >> number; //Will get two numbers, stopping at once space.
- if (number == "Q" || number == "q" || indexer == "Q" || indexer == "q")
- break;
- int val = atof(number.c_str( )); //Turn into an int
- //cout << "D: Turning val " << number << " into " << val;
- int ind = atoi(indexer.c_str( ));//Turn into an int
- //cout << "\nD: Turning ind " << indexer << " into " << ind;
- cin.ignore(1000, 10); //Clear buffer
- //if (val != 0) // Edge case for our duplicate checking loop here
- //{
- bool dupe = false;
- //int whereDupe;
- for(int x = 0; x < place; x++) // Scrubs unique index tracker
- { // Array to see if new val is
- if(ind == indexes[x]) // identical to once inside.
- {
- dupe = true;
- }
- }
- if(!dupe && ind >= 0 && ind <= 99)
- {
- indexes[place] = ind;
- place++;
- }
- nums[ind] = val;
- } // end of entering loop
- // STATISTICS OUTPUT
- cout << "\n\nYou've entered " << place << " awesome numbers." << endl;
- cout << "\nHere are the transcribed locations and their amounts:" << endl;
- for(int i = 0; i < nums.getCapacity(); i++) //Print out non-zero indexes
- if (nums[i] != 0)
- cout << "\n\t" << i << " => " << nums[i];
- // ENTERING SEARCH MODE
- cout << "\n\n Entering index search mode...";
- while(true)
- {
- cout << "\n Give me an tasty index location, or enter Q to abandon me: ";
- cin >> indexer; // Reusing the now useless counting string, how efficient?
- if (indexer == "Q" || indexer == "q")
- break;
- place = atoi(indexer.c_str( )); // Turn old loop counter into search variable.
- if (place >= 0 && place <= 99 && nums[place] != 0)
- {
- cout << "Gotcha! The value at " << place << " is " << nums[place];
- }
- else
- {
- cout << "... I have nothing at. " << place << ". Apologies.";
- }
- }// end of search loop
- /*
- // Introduction
- cout << "Welcome to MyStaticArray driver program." << endl;
- // Initializing values
- Array<double, 100> array;
- string val1;
- int size = 0;
- int index;
- int i;
- // This loop completes the user's population for the array's size.
- for (i = 0; i < array.getCapacity(); i++) {
- cout << "\nPlease enter location " << i
- << "'s desired data (Q/q to exit entry): ";
- cin >> val1;
- cin.ignore(1000, 10);
- if (val1 == "q" || val1 == "Q") {
- break;
- } else {
- array[i] = atof(val1.c_str());
- }
- size++;
- }
- // List their unique entries.
- cout << "\nThe unique entries are: ";
- for (i = 0; i < size; i++) {
- cout << array[i] << " ";
- }
- // Search mode!
- cout << "\n\nData entry search mode!" << endl
- << "\nPlease enter the data that you want to search(Or Q/q to exit): ";
- cin >> val1;
- while (val1 != "q" && val1 != "Q") {
- index = array.scan(atoi(val1.c_str()));
- if (index != -1)
- {
- cout << "\n Found! The position of " << val1 << " is " << index << ".\n";
- } else {
- cout << "Sorry, I could not find that value.";
- }
- cout << "\n Please enter another value to search for(Q/q to exit): ";
- cin >> val1;
- }
- return 0;
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement