From a89971553e39f90c021d7197420afb3edbe68d40 Mon Sep 17 00:00:00 2001 From: Skyrain25 Date: Wed, 25 Jan 2017 11:54:30 -0400 Subject: [PATCH 1/6] Added header file --- Account.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Account.h diff --git a/Account.h b/Account.h new file mode 100644 index 0000000..f189f72 --- /dev/null +++ b/Account.h @@ -0,0 +1,21 @@ +#ifndef ACCOUNT_H +#define ACCOUNT_H +#include +#include +using namespace std; + +class Account +{ + private: + string name; + int acct_num; + + public: + Account ( ); + void setName (string); + string getName ( ); + void setNum (int); + int getNum ( ); +}; +#endif + From 1cbd9dc9c192458cfced27a2b687e38275a2457d Mon Sep 17 00:00:00 2001 From: Skyrain25 Date: Wed, 25 Jan 2017 11:56:10 -0400 Subject: [PATCH 2/6] Added implementation file --- Account.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Account.cpp diff --git a/Account.cpp b/Account.cpp new file mode 100644 index 0000000..996f3af --- /dev/null +++ b/Account.cpp @@ -0,0 +1,28 @@ +#include +#include +#include "Account.h" + +using namespace std; + +Account::Account( ) +{ + name = ""; + acct_num = 0; +} +void Account::setName (string accountName) +{ + name = accountName; +} +string Account:: getName ( ) +{ + return name; +} +void Account::setNum (int a) +{ + acct_num = a; +} +int Account::getNum ( ) +{ + return acct_num; +} + From dd0b444d94cc1c61535036faac37128c1a87db3d Mon Sep 17 00:00:00 2001 From: Skyrain25 Date: Wed, 25 Jan 2017 11:57:24 -0400 Subject: [PATCH 3/6] Added client file --- Main.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Main.cpp diff --git a/Main.cpp b/Main.cpp new file mode 100644 index 0000000..7f3d038 --- /dev/null +++ b/Main.cpp @@ -0,0 +1,32 @@ +#include "Account.h" +#include +#include + +using namespace std; + +int main( ) +{ + Account myAccount; + vector acctList; + + myAccount.setName ("Bob"); + myAccount.setNum (12); + acctList.push_back (myAccount); + myAccount.setName ("Tim"); + myAccount.setNum (10); + acctList.push_back(myAccount); + myAccount.setName ("Rich"); + myAccount.setNum (35); + acctList.push_back (myAccount); + myAccount.setName ("Chris"); + myAccount.setNum (66); + acctList.push_back (myAccount); + + for (int i = 0; i < acctList.size ( ); i++) + { + cout << acctList[i].getName()<< "" << acctList[i].getNum (); + + } + +} + From 467c1d4bb6a1956ddeea67cb5781db6b4515ca40 Mon Sep 17 00:00:00 2001 From: Skyrain25 Date: Wed, 25 Jan 2017 12:02:57 -0400 Subject: [PATCH 4/6] Modified main --- Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Main.cpp b/Main.cpp index 7f3d038..162bfb1 100644 --- a/Main.cpp +++ b/Main.cpp @@ -1,4 +1,4 @@ -#include "Account.h" +#include "Account.cpp" #include #include From 58f85e8795dd8a322ea28f273d42e477cd327368 Mon Sep 17 00:00:00 2001 From: Skyrain25 Date: Wed, 8 Feb 2017 12:22:25 -0400 Subject: [PATCH 5/6] Implemented linear search --- Main.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/Main.cpp b/Main.cpp index 162bfb1..364cf41 100644 --- a/Main.cpp +++ b/Main.cpp @@ -4,8 +4,23 @@ using namespace std; +int linearSearch(auto data, auto key) + { + for (int i=0; i acctList; @@ -22,11 +37,21 @@ int main( ) myAccount.setNum (66); acctList.push_back (myAccount); - for (int i = 0; i < acctList.size ( ); i++) + /*for (int i = 0; i < acctList.size ( ); i++) { cout << acctList[i].getName()<< "" << acctList[i].getNum (); - } - + }*/ + + cout << "Enter search key: "; + cin >> search_key; + + result = linearSearch(acctList, search_key); + + if (result == -1) + cout<<"not found"; + else + cout<<"found at index "< Date: Wed, 8 Feb 2017 12:24:19 -0400 Subject: [PATCH 6/6] Added linear search --- Main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Main.cpp b/Main.cpp index 364cf41..365af41 100644 --- a/Main.cpp +++ b/Main.cpp @@ -49,9 +49,9 @@ int main( ) result = linearSearch(acctList, search_key); if (result == -1) - cout<<"not found"; - else - cout<<"found at index "<