Advertisement
Guest User

the CPP

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.25 KB | None | 0 0
  1. // Written by Karl Hou
  2. // Student ID: 1445202
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <cstdlib>
  7. #include "MyStaticArray.h"
  8.  
  9. using namespace std;
  10. #include "MyStaticArray.h"
  11.  
  12. int main() {
  13.  
  14.     string number;            // Number they want to input
  15.     string indexer;           // Where they want to store the number
  16.     Array<double, 100> nums;  // 1st Array, for actual nums
  17.     Array<int, 100> indexes;  // 2nd Array, to keep track of ints
  18.     int place = 0;            // While loop counter for later
  19.  
  20.     cout << "\n\nWELCOME to the FANTASTICAL and FANTASIMICAL Array driver!"; //Intro
  21.  
  22.     // VALUE ENTERING LOOP
  23.  
  24.     while (true)    //Infinite while loop with a break on Q. Array is only 100 long
  25.     {
  26.         //but oh well.
  27.         cout << "\nAt what location will you put what? [Q in either to quit]: ";
  28.         cin >> indexer >> number;        //Will get two numbers, stopping at once space.
  29.         if (number == "Q" || number == "q" || indexer == "Q" || indexer == "q")
  30.             break;
  31.         int val = atof(number.c_str( )); //Turn into an int
  32.         //cout << "D: Turning val " << number << " into " << val;
  33.         int ind = atoi(indexer.c_str( ));//Turn into an int
  34.         //cout << "\nD: Turning ind " << indexer << " into " << ind;
  35.         cin.ignore(1000, 10);            //Clear buffer
  36.  
  37.         //if (val != 0) // Edge case for our duplicate checking loop here
  38.         //{
  39.         bool dupe = false;
  40.         //int whereDupe;
  41.         for(int x = 0; x < place; x++) // Scrubs unique index tracker
  42.         {                                // Array to see if new val is
  43.             if(ind == indexes[x])        // identical to once inside.
  44.             {
  45.                 dupe = true;
  46.  
  47.             }
  48.         }
  49.  
  50.         if(!dupe && ind >= 0 && ind <= 99)
  51.         {
  52.             indexes[place] = ind;
  53.             place++;
  54.         }
  55.         nums[ind] = val;
  56.  
  57.     } // end of entering loop
  58.  
  59.     // STATISTICS OUTPUT
  60.  
  61.     cout << "\n\nYou've entered " << place << " awesome numbers." << endl;
  62.     cout << "\nHere are the transcribed locations and their amounts:" << endl;
  63.     for(int i = 0; i < nums.getCapacity(); i++) //Print out non-zero indexes
  64.         if (nums[i] != 0)
  65.             cout << "\n\t" << i << " => " << nums[i];
  66.  
  67.     // ENTERING SEARCH MODE
  68.  
  69.     cout << "\n\n Entering index search mode...";
  70.  
  71.     while(true)
  72.     {
  73.         cout << "\n Give me an tasty index location, or enter Q to abandon me: ";
  74.         cin >> indexer; // Reusing the now useless counting string, how efficient?
  75.  
  76.         if (indexer == "Q" || indexer == "q")
  77.             break;
  78.         place = atoi(indexer.c_str( )); // Turn old loop counter into search variable.
  79.  
  80.         if (place >= 0 && place <= 99 && nums[place] != 0)
  81.         {
  82.             cout << "Gotcha! The value at " << place << " is " << nums[place];
  83.         }
  84.         else
  85.         {
  86.             cout << "... I have nothing at. " << place << ". Apologies.";
  87.         }
  88.     }// end of search loop
  89.  
  90.  
  91.   /*
  92.   // Introduction
  93.   cout << "Welcome to MyStaticArray driver program." << endl;
  94.  
  95.   // Initializing values
  96.   Array<double, 100> array;
  97.   string val1;
  98.   int size = 0;
  99.   int index;
  100.   int i;
  101.  
  102.   // This loop completes the user's population for the array's size.
  103.   for (i = 0; i < array.getCapacity(); i++) {
  104.     cout << "\nPlease enter location " << i
  105.     << "'s desired data (Q/q to exit entry): ";
  106.     cin >> val1;
  107.     cin.ignore(1000, 10);
  108.     if (val1 == "q" || val1 == "Q") {
  109.       break;
  110.     } else {
  111.       array[i] = atof(val1.c_str());
  112.     }
  113.     size++;
  114.   }
  115.  
  116.   // List their unique entries.
  117.   cout << "\nThe unique entries are: ";
  118.   for (i = 0; i < size; i++) {
  119.     cout << array[i] << " ";
  120.   }
  121.  
  122.   // Search mode!
  123.   cout << "\n\nData entry search mode!" << endl
  124.        << "\nPlease enter the data that you want to search(Or Q/q to exit): ";
  125.   cin >> val1;
  126.  
  127.   while (val1 != "q" && val1 != "Q") {
  128.     index = array.scan(atoi(val1.c_str()));
  129.     if (index != -1)
  130.     {
  131.       cout << "\n Found! The position of " << val1 << " is " << index << ".\n";
  132.     } else {
  133.       cout << "Sorry, I could not find that value.";
  134.     }
  135.     cout << "\n Please enter another value to search for(Q/q to exit): ";
  136.     cin >> val1;
  137.   }
  138.  
  139.   return 0;
  140.   */
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement