Question

In: Computer Science

create code for an address book console program in C++ that: Uses a basic array in...

create code for an address book console program in C++ that:

  1. Uses a basic array in the main program to hold multiple Record class objects.
  2. A Record class is to be constructed with the following member variables:
    1. Record number,
    2. first name,
    3. last name,
    4. age, and
    5. telephone number.
  3. The Record class must have a custom constructor that initializes the member variables.
  4. The Record class declaration is to be separated from the Record class implementation and these are to be placed in .h and .cpp files respectively.
  5. The program should have a perpetual menu that allows a choice of:
    1. Input information into an record,
    2. Display all information in all records, and
    3. Exit the program.
  6. The program should hold 10 records at the minimum.

Solutions

Expert Solution

#include <iostream>
#include <string>
using namespace std;
class Record{ //.H FILE RECORD
private: //PRIVATE MEMBER
int recordNumber;
string firstName;
string lastName;
int age;
int telePhone;
public:
Record(); //DEFAULT CONSTRUCTOR
Record(int,string,string,int,int); // PARAMETERIZE
void display(); // DISPLAY FUN
void setData(int,string,string,int,int); // EXTRA FUN MUTATOR
};
Record::Record(){
recordNumber=0;
age=0;
telePhone=0;
// STRING IS NULL BY DEFAULT
}
Record::Record(int rec, string first, string last, int ag, int phone){
// PARAMETERIZE CONSTRUCTOR
recordNumber=rec;
firstName=first;
lastName=last;
age=ag;
telePhone=phone;
}
void Record::setData(int rec, string first, string last, int ag, int phone){
recordNumber=rec;
firstName=first;
lastName=last;
age=ag;
telePhone=phone;
}
void Record::display(){ //DISPLAY FUNCTION
cout<<"Record Number: "<<recordNumber<<endl;
cout<<"First Name: "<<firstName<<endl;
cout<<"Last Name: "<<lastName<<endl;
cout<<"Age: "<<age<<endl;
cout<<"Telephone: "<<telePhone<<endl;
}
void menu(){ //MENU
cout<<endl;
cout<<"----------------- MENU -----------------"<<endl;
cout<<"| Press 1 to Insert |"<<endl;
cout<<"| Press 2 to Display |"<<endl;
cout<<"| Press 3 to exit |"<<endl;
cout<<"----------------------------------------"<<endl;
}
int main()
{
int count=0;
int reco,ag,phone,choice;
string first,last;
int size=10;
Record rec[10];
while(1){
menu();
cout<<"Enter choice: ";
cin>>choice;
if(choice==1){
if(count==10){
cout<<"Array is full"<<endl;
}
else{
cout<<"Enter record number: ";
cin>>reco;
cout<<"Enter first name: ";
cin.ignore();
getline(cin,first);
cout<<"Enter last name: ";
cin.ignore();
getline(cin,last);
cout<<"Enter age: ";
cin>>ag;
cout<<"Enter telephone Number: ";
cin>>phone;
rec[count].setData(reco,first,last,ag,phone);
count++;
}
}
else if(choice==2){
if(count==0){
cout<<"Array is empty"<<endl;
}
else{
for(int i=0;i<count;i++){
rec[i].display();
}
}
}
else if(choice ==3){
return 0;
}
else{
cout<<"Invalid option"<<endl;
}

}
return 0;
}

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW

PLEASE GIVE A THUMBS UP


Related Solutions

In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
Language: c++ works in visual basic Write a program that uses an array of nested structs...
Language: c++ works in visual basic Write a program that uses an array of nested structs to store the addresses for your store’s customers.  Each customer has a name and two addresses: home address and business address.  Each address has a street, city, state, and zip code. Requirements: 1. Data structure a. Define an Address struct with street, city, state and zip fields b. Define a Customer struct with lastNm and firstNm fields, plus homeAddr and busAddr fields...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Design a C++ program An address book is a book or a database used for saving...
Design a C++ program An address book is a book or a database used for saving and storing contacts which may usually consists of a few standard fields (for example: first name, last name, company name, address, telephone number, e-mail address, fax number, mobile phone number). Design an online address book to keep track of the details of family members, close friends and certain business associates. Details which your designed address book will keep should be like names (first name,...
Submit a well-commented C program.   Create code. That will build a random 8x8 2D array of...
Submit a well-commented C program.   Create code. That will build a random 8x8 2D array of small-case characters. Demonstrate how it functions by printing out the result on your screen. Add a function will print out a single line of the array. If the user enters a value between 0 and 7 to select to print out a single row of the original 2D array.                void printLine(char *,int);    // This is the prototype declaration             void printLine(char myArr[][])     //...
Create a console app with C# that uses a while loop to calculate the average of...
Create a console app with C# that uses a while loop to calculate the average of 3 test scores. Input integers, but use the appropriate average data type. Generally, you use a while to do something while a condition is true. You can use a while loop to execute a certain number of times. *While* this is not the best use of the while loop and another loop is generally more appropriate, it follows the pattern below set a counter...
Create a program in java with the following information: Design a program that uses an array...
Create a program in java with the following information: Design a program that uses an array with specified values to display the following: The lowest number in the array The highest number in the array The total of the numbers in the array The average of the numbers in the array Initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51 example...
In this project you will create a basic console based calculator program. The calculator can operate...
In this project you will create a basic console based calculator program. The calculator can operate in two modes: Standard and Scientific modes. The Standard mode will allow the user to perform the following operations: (+, -, *, /) add, subtract, multiply, and divide The Scientific mode will allow the user to perform the same functionality as the Standard add, subtract, multiply, and divide (+, -, *, / ) plus the following: sin x, cos x, tan x. (sin x,...
In C# using a Console App, create an array that stores 20 integer values. Use the...
In C# using a Console App, create an array that stores 20 integer values. Use the random number generator to select an integer value between 0 and 10. Store the 20 random integers in the array. Once the array has been created: Print the values in the array. Print the values in the array in reverse order. Sort and print the values in the array in ascending order. Sort and print the values in the array in descending order. Count...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT