LIBPB.C #include \"libpb.h\" #include <string.h> #include <stdio.h> void add_per
ID: 3715793 • Letter: L
Question
LIBPB.C
#include "libpb.h"
#include <string.h>
#include <stdio.h>
void add_person(struct phone_book * pb, struct personal_info person){
pb->people[pb->num_people] = person;
pb->num_people++;
return;
}
void search_pb(struct phone_book pb, char find_name[]){
int num_found = 0;
for(int i = 0; i < pb.num_people; i++) {
if(!strcmp(find_name,pb.people[i].first)) {
printf(" Name: %s %s Phone: %s ", pb.people[i].first, pb.people[i].last, pb.people[i].phone);
num_found++;
}
}
if(num_found == 0) {
printf("No entries with that name. ");
}
return;
}
LIBPB.H
#ifndef __LIBPB_H__
#define __LIBPB_H__
struct personal_info {
char first[25];
char last[25];
char phone[15];
};
struct phone_book {
struct personal_info people[20];
int num_people;
};
void add_person(struct phone_book * pb, struct personal_info person);
void search_pb(struct phone_book pb, char find_name[]);
#endif
Explanation / Answer
class personal_info{
private:
string first;
string last;
string phone;
public:
void setfirst(string a){
first = a;;
}
void setlast(string a){
last = a;;
}
void setphone(string a){
phone = a;;
}
string getfirst(){
return first;
}
string getlast(){
return last;
}
string getphone(){
return phone;
}
}
class phone_book{
private:
vector<personal_info> data;
public:
void add_person(personal_info p){
data.push_back(p);
}
void search_pb(string p){
for (int i = 0; i<data.size(); i++){
if (data[i].getfirst() == p){
cout << "Name: " << data[i].getfirst() << " " << data[i].getlast() << " " << "Phone:" << data[i].getphone() << endl;
return;
}
}
cout << "Not found ";
}
int get_num_people(){
return data.size();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.