Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added hellogit.out
Binary file not shown.
98 changes: 98 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <iostream>
#include <string>
#include "test.h"
#include <vector>
using namespace std;


int linearSearch(vector<Test> A, string key, char aChar) {


for(int i = 0; i < A.size(); i ++) {

if (A[i].getString() == key){
return i;

}

if (A[i].getChar() == aChar){
return i;
}

}
return -1;
}


int main (){
string input = "";
char xChar = 'c';
string string1 = "";
int xnum1 = 0;
int xnum2 = 0;
char xChar2 = 'p';
char xChar3 = '\0';
Test testObj; // object
Test testObj2;
Test testObj3;
Test testObj4;
vector <Test> objVect;

cout << "Enter 3 characters and a string: " << endl;
cin >> xChar;
cin >> xChar2;
cin >> xChar3;
cin >> string1;





//testObj.setVect(xChar, string1, xnum1, xnum2);
//objVect.push_back(testObj);

testObj.setChar(xChar3);
testObj2.setChar(xChar);
testObj3.setVect(xChar, string1);
testObj4.setChar(xChar2);

objVect.push_back(testObj);
objVect.push_back(testObj3);

objVect.push_back(testObj2);
objVect.push_back(testObj4);



for(int x = 0; x < objVect.size(); x++) {

cout << objVect[x].getString();


cout << objVect[x].getChar() << endl;


}
char hChar = '\0';
int result = 0;
while(cin >> input >> hChar)//perform searches until Ctrl + D entered
{

result = linearSearch(objVect, input, hChar);

cout<<" "<< input <<" was ";

if (result == -1)
cout<<"not found";
else
cout<<"found at position "<< result;


cout<<endl<<endl<<"Enter a value to search for: ";

}


}


46 changes: 46 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <string.h>
#include "test.h"
#include <iostream>

Test::Test(){
char char1 = '\0';
string sent = "";
string stri = "";
char cha = '\0';
int number1 = 0;
int number2 = 0;


}


void Test::setChar(char char1) {

cha = char1;
}

char Test::getChar(){
return cha;

}


void Test::setString(string sent) {

stri = sent;
}

string Test::getString(){
return stri;

}



void Test::setVect(char ch, string sent){
cha = ch;
stri = sent;

}


32 changes: 32 additions & 0 deletions test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <string.h>
#include <iostream>
#include <vector>
#ifndef TEST_H
#define TEST_H
using namespace std;

class Test{
private:

char cha;
string stri;
//vector <Pair> objVect (char, string);

public:

void setChar(char char1);
char getChar();

void setString (string sent);
string getString();

//void setRep(char ch, string strin);



void setVect(char ch, string sent);
Test();

};

#endif