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
30 changes: 30 additions & 0 deletions Phone.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
#include <vector>
#include "Phone.h"
using namespace std;

phone::phone (string n , double c){
phoneType= n;
phoneCost= c;
}

void phone::setPhoneType(string n){
phoneType=n;
}

string phone::getPhoneType(){
return phoneType;
}

void phone::setPhoneCost(double c){
phoneCost= c;
}

double phone::getPhoneCost(){
return phoneCost;
}

void phone::outputMessage(){
cout << "Your choice of phone: " << phoneType << endl;
cout<< "The accompanied cost is: " << phoneCost << endl;
}
19 changes: 19 additions & 0 deletions Phone.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
s#include <iostream>
#include <string>
#include <vector>
using namespace std;

class phone{
private:
string phoneType;
double phoneCost;


public:
phone (string = "", double = 0.0);
void setPhoneType(string n);
string getPhoneType();
void setPhoneCost(double c);
double setPhoneCost();
void outputMessage();
};
63 changes: 63 additions & 0 deletions Source.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
#include <string>
#include <vector>
#include "Phone.h"
using namespace std;

int linearSearch(auto myPhone, auto key);

int main(){
string type;
string search_key;
double cost;
int answer;


vector <phone> myPhone;
cout<<"Enter a brand of phone" ;
cin>>type;
myPhone.push_back(type);

while (type != "#"){
myPhone.push_back(type);
cin>>type;
}

cout<< "Number of types entered ="<<myPhone.size()<<endl;
cout<<" Enter search key:";
cin>>search_key;

while(search_key != "#")
{
answer = linearSearch(myPhone,search_key);

cout<<" '"<<search_key<<"' was ";

if (answer == -1)
cout<<"not found";
else
cout<<"found at index "<<answer;


cout<<endl<<endl<<"Enter a value to search for: ";
cin>>search_key;
}



/*
cout<<"My vector contains:"<<myPhone.size();
*/
}

int linearSearch(auto myPhone, auto key){
for (int i=0; i<myPhone.size(); i++){
if (myPhone[i].getPhoneType() == key){
return i;
}
}
return -1;
}