Professional Documents
Culture Documents
3 e 82 F 10 A 3 F 19 CDF 757 D 5
3 e 82 F 10 A 3 F 19 CDF 757 D 5
/*
Isaac Bernal
Fundamentals of Programming 2
Professor Lara
4/14/22
This program demonstrates the use of linear search on a list of faculty members' first name, last
name, and I.D.
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "Faculty.h"
using namespace std;
//Function Prototypes
void welcome();
int LinearSearch(Faculty[], int, string);
int getData(Faculty[], const int );
void getKey(string&);
void printData(Faculty[], int);
int main() {
const int SIZE = 50;
Faculty instructorArray[SIZE];//Class Array
ifstream inputfile;//to access files
string searchKey;//user's search
int lcount;//total members in array
int keyCount;//location of last name
welcome();
do
{
getKey(searchKey);
printData(instructorArray, keyCount);
return 0;
}
//Function Definitions
//***********************************************************
void welcome()
{
cout << "\t\t_-_Welcome To Faculty Member Search_-_\n\n";
}
//***********************************************************
//To Receive the last name and search through array to find the matching last name
// Returns the counter in which the last name sits on the array
int LinearSearch(Faculty listArray[], int size, string key)
{
int counter;
for (counter = 0; counter < size; ++counter) //loop to access each the objects in array
{
if (listArray[counter].getLastName() == key)//When name is found matching the array variable
{
return counter;
}
}
return -1;//if not found
}
//***********************************************************
//Reads the text file and store in array
//returns the counter of total members of the array
int getData(Faculty arrayN[], const int SIZE)
{
istringstream inSS;//each members data is in a single line
ifstream inputfile;// to access txt file
inputfile.open("list.txt");
string lineString;
arrayN[counter].setID(iD);
inputfile.close();
return counter;
}
//***********************************************************
void printData(Faculty fArray[], int keyCount)
{
cout << "\tName: " << fArray[keyCount].getLastName() << ", " <<
fArray[keyCount].getFirstName() << "\n\tFaculty I.D.: " << fArray[keyCount].getID();
}
//***********************************************************
//Asks user for the last name
void getKey(string& sKey)
{
cout << "Enter Last Name of Faculty Member: ";
cin >> sKey;
}
//* --- This file is the IMPLEMENTATION FILE ---
#include <string>
using namespace std;
#include "Faculty.h"
void Faculty::setLastName(string l)
{
lastName = l;
}
void Faculty::setID(short i)
{
facultyID = i;
}
string Faculty::getFirstName()
{
return firstName;
}
string Faculty::getLastName()
{
return lastName;
}
short Faculty::getID()
{
return facultyID;
}
/*
--- This file is the SPECIFICATION FILE ---
*/
#include <string>
using namespace std;
#ifndef FACULTY_H
#define FACULTY_H
class Faculty
{
private:
string lastName;
string firstName;
short facultyID;
public:
//Prototypes
void setFirstName(string f);
void setLastName(string l);
void setID(short i);
string getFirstName();
string getLastName();
short getID();
};
#endif