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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include <iostream>
#include <string>
#include <fstream> //you must include this library if you wish to do file i/o
#include <stack>
using namespace std;
class order_record
{
public:
string cell_number;
string item_number;
double quantity;
double price;
int processing_plant;
double tax_rate;
double order_tax;
double net_cost;
double total_cost;
};
void initialize(order_record * & INV, int & count, int & size);
int search(order_record * INV, int count, string key);
void initialize(order_record * & INV, int & count, int & size)
{
count = 0;
size = 25;
INV = new order_record[size];
ifstream in;
in.open("purchase_data8.txt");
if (in.fail())
{
cout << "INPUT file did not open correctly" << endl;
cout << "Program cannot execute." << endl;
//pops up if file was not open and
//there for the rest of program cannot execute
}
else
{
while (!in.eof() && count < size)
{
//if (is_full(count, size))
//{
// double_size(INV, count, size);
//}
//reads data that was read in file one record at a time
//prints into new file
//using ofstream objecty
in >> INV[count].cell_number;
in >> INV[count].item_number;
in >> INV[count].quantity;
in >> INV[count].price;
in >> INV[count].processing_plant;
count++;
}
}
in.close();
}
int search(order_record * INV, int count, string key)
{
//integer function that has three formal parameters
//array of records INV; input parameter count; input parameter key;
//which is the cell phone for record you are searching for
//function return the location of key in INV
//if it is there is same
//otherwise -1 is returned
//searches through doc
//key 9546321555 at 0, 1 , 11
//key 9042224556 at 9, 19, 23
for(int i =0; i<count; i++)
{
//cout << "Loop FOR i: " << i << '\n';
if(INV[i].cell_number == key)
{
//cout << "Cell Numbers " << INV[i].cell_number << '\n';
cout << "Loop IF i: " << i << '\n';
//returns singular because int
//if you want next in line then search has to be called again
//made to skip the one previously it found and
//then continue searching for the next int
return i;
}
}
return -1;
}
int main() {
int count = 0; //initializing count
int size;
string key;
order_record * INV = 0; //declaring the dynamic array
//Test 1:
cout << "**********************************************************************\n";
//void initialize(order_record * & INV, int & count, int & size);
cout << "Test 1: Testing initialize, double_size, process, is_full" << '\n';
initialize(INV, count, size);
cout << "End of Test 1" << '\n';
//cout << "**********************************************************************\n";
//Test 4:
cout << "**********************************************************************\n";
cout << "Test 4: Testing bool search" << '\n';
//key 9546321555 at 0, 1 , 11
//key 9042224556 at 9, 19, 23
//int i = 0;
//int repeat[i] ; //initializes to size of og array
cout << "Please input key: " << '\n';
cin >> key;
//once search gives location check
//if there are any others in array
for(int i =0; i < count && (i = search(INV + i, count - i, key) != -1); i++){
//singular int from the search function?
//cout << "Key in the main FOR loop search: " << i << '\n';
if(i != count)
{
//omits i but neg statment so only i
cout << "Key in the main IF loop search: " << i << '\n';
//is it possible to continue counting
//the key past the first time int is found?
}
//break;
}
cout << "BYE BYE" << endl;
return 0;
}
|