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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: katherine weisbrod
*
* Created on June 6, 2018, 9:58 PM
*/
#include <cstdlib>
#include <iostream>
#include <istream>
#include <string>
#include <iomanip>
using namespace std;
void displayMenu();
void printContact(string[], string[], long int, int);
void sortAscending(string[], string[], long int, int);
void sortDescending(string[], string[], long int, int);
void searchContact(string[], string[], long int, int);
void getFirstName (string[], int);
void getLastName (string[], int);
void getPhoneNumber (long int[], int);
/*
*
*/
int main(int argc, char** argv)
{//Declare variables
int menuChoice = 0;
string firstName[3];
firstName[0] = "Maria";
firstName[1] = "Thomas";
firstName[2] = "Harold";
string lastName[3];
lastName[0] = "Neptune";
lastName[1] = "Quinn";
lastName[2] = "Apple";
long int number[3];
number[0] = 4352869;
number[1] = 7658974;
number[2] = 9568231;
int size = -1;
printContact(firstName, lastName, number, 3);
//get menu choice
displayMenu();
cout << "Enter 1, 2, 3, 4, 5, or 6: ";
cin >> menuChoice;
while (menuChoice > 0 && menuChoice < 6)
{
//assign menu functions
switch (menuChoice)
case 1:
{
getFirstName(firstName, 3);
getLastName(lastName, 3);
getPhoneNumber(number, 3);
break;
}
case 2:
{
sortAscending(firstName, lastName, number, 3);
break;
}
case 3:
{
sortDescending(firstName, lastName, number, 3);
break;
}
case 4:
{
printContact(firstName, lastName, number, 3);
break;
}
case 5:
{
searchContact(firstName, lastName, number, 3);
break;
}
case 6:
{
break;
}
default:
{
cout << "Enter a valid Menu Option!!" << endl;
break;
}
//get menu choice
displayMenu();
cout << "Enter 1, 2, 3, 4, 5, or 6: ";
cin >> menuChoice;
} //end while
//system("pause");
return 0;
//end of main function
}
//*****function definitions*****
void displayMenu()
{
cout << "1 Input data" << endl;
cout << "2 Sort data Ascending" << endl;
cout << "3 Sort data Descending" << endl;
cout << "4 Print all data" << endl;
cout << "5 Search for an individual in the data" << endl;
cout << "6 End program" << endl;
} //end of displayMenu function
void getFirstName (string arrayFirstName[], int size, int index)
{
for (index=0; index< size; index++)
{
cout << "Please enter the first name and press enter: ";
cin >> arrayFirstName[index];
cout << endl;
}
}
void getLastName (string arrayLastName[], int size, int index)
{
for (index=0; index< size; index++)
{
cout << "Please enter the last name and press enter: ";
cin >> arrayLastName[index];
cout << endl;
}
}
void getPhoneNumber (long int arrayNumber[], int size, int index)
{
for (index=0; index< size; index++)
{
cout << "Please enter the phone number without hyphens and press enter: ";
cin >> arrayNumber[index];
cout << endl;
}
}
void printContact(string arrayFirstName[], string arrayLastName[], long int arrayNumber[],int size)
{
for (index = 0; index < size; index++)
{
cout << arrayFirstName[index] << endl;
cout << arrayLastName[index] << endl;
cout << arrayNumber[index] << endl;
}
}
void sortAscending(string arrayFirstName[], string arrayLastName[], long int arrayNumber[], int size)
{
for (int i=0; i < size -1; i++ )
{
for (int j=0; j<size-i-1;j++)
{
if (arrayFirstName[j]>arrayFirstName[j+1])
{
arrayFirstName[j]=arrayFirstName[j+1];
arrayLastName [j]=arrayLastName[j+1];
arrayNumber[j] = arrayNumber[j+1];
} //End If statement
} //End nested for loop
} //End for loop
}
void sortDescending(string arrayFirstName[], string arrayLastName[], long int arrayNumber[], int size)
{
for (int i=0; i < size -1; i++ )
{
for (int j=0; j<size-i-1;j++)
{
if (arrayFirstName[j]<arrayFirstName[j+1])
{
arrayFirstName[j]=arrayFirstName[j+1];
arrayLastName [j]=arrayLastName[j+1];
arrayNumber[j] = arrayNumber[j+1];
} //End If statement
} //End nested for loop
} //End for loop
}
void searchContact(string arrayFirstName[], string arrayLastName[], long int arrayNumber[], int size)
{
bool found = false;
string userInput;
index = 0;
cout << "Enter Name to Search" << endl;
cin >> userInput;
if (arrayFirstName[index] ==userInput || arrayLastName[index] == userInput)
{
cout << arrayFirstName[index] << endl;
cout << arrayLastName[index] << endl;
cout << arrayNumber[index] << endl;
cout << endl;
found = true;
} //End if statement
if (found==false) //If searched target not found
{
cout << "Contact not found." << endl;
}
}
|