Question

In: Computer Science

Write a short and simple C++ program (must be able to have custom inputs): Design a...

Write a short and simple C++ program (must be able to have custom inputs):

Design a class that holds the following personal data:

name, address, age, and phone number

Write appropriate accessor and mutator functions. Demonstrate the class by writing a program that creates three instances of it. One instance should hold your information, and the other two should hold your friends' or family members' information.

Thanks!!

Solutions

Expert Solution

Solution:

#include<string>
#include<iostream>
using namespace std;
class Details
{
   string name;
   string address;
   int age;
   string phone;
  
   public:
       Details()
       {
           this->name="X";
           this->address="Y";
           this->age=0;
           this->phone="0000000000";          
       }      
       Details(string name,string address,int age,string phone)
       {
           this->name=name;
           this->address=address;
           this->age=age;
           this->phone=phone;
       }
       void setName(string name)
       {
           this->name=name;
       }
       void setAddress(string address)
       {
           this->address=address;
       }      
       void setAge(int age)
       {
           this->age=age;
       }
       void setPhone(string phone)
       {
           this->phone=phone;
       }
       string getName()
       {
           return name;
       }
       string getAddress()
       {
           return address;
       }
       int getAge()
       {
           return age;
       }
       string getPhone()
       {
           return phone;
       }
};
void display(Details d)
{
   cout<<"\n\nDetails";
   cout<<"\nName:"<<d.getName();
   cout<<"\nAddress:"<<d.getAddress();
   cout<<"\nAge:"<<d.getAge();
   cout<<"\nPhone Number:"<<d.getPhone();
}
int main()
{
   string name,address,phone;
   int age;
  
   cout<<"Enter your Details\n";
   cout<<"Enter your Name:";
   cin>>name;
   cout<<"Enter your Address:";
   cin>>address;
   cout<<"Enter your Age:";
   cin>>age;
   cout<<"Enter your Phone Number:";
   cin>>phone;
   Details d1(name,address,age,phone);
  
   cout<<"\nEnter Details of friend1/family member1\n";
   cout<<"Enter your Name:";
   cin>>name;
   cout<<"Enter your Address:";
   cin>>address;
   cout<<"Enter your Age:";
   cin>>age;
   cout<<"Enter your Phone Number:";
   cin>>phone;
   Details d2(name,address,age,phone);
  
   cout<<"\nEnter Details of friend2/family member2\n";
   cout<<"Enter your Name:";
   cin>>name;
   cout<<"Enter your Address:";
   cin>>address;
   cout<<"Enter your Age:";
   cin>>age;
   cout<<"Enter your Phone Number:";
   cin>>phone;
   Details d3(name,address,age,phone);
      
   display(d1);
   display(d2);
   display(d3);
  
   return 0;
  
}
Output:


Related Solutions

Write a program in C (NOT C++ or C#) The program inputs 5 elements into each...
Write a program in C (NOT C++ or C#) The program inputs 5 elements into each of 2 integer arrays. Multiply corresponding array elements, that is, arrayOne[0] * arrayTwo[0], etc. Save the product into a third array called prodArray[ ]. Display the product array.
Design a simple calculator program using C++ which is able to: 1. ADD two decimal numbers...
Design a simple calculator program using C++ which is able to: 1. ADD two decimal numbers 2. MULTIPLY two decimal numbers. The following features must be incorporated in your program. 1. Must have an interface for the user to be able to either select the ADD option or MULTIPLY option or to EXIT the program. NOTE: If the user makes a wrong selection, a display must be shown to inform the user and the user must be given a choice...
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
1. Write a program in C++ that takes as inputs a positiveinteger n and a...
1. Write a program in C++ that takes as inputs a positive integer n and a positive double a. The function should compute the geometric sum with base a up to the powern and stores the result as a protected variable. That is, the sum is: 1 + ? + ? ^2 + ? ^3 + ? ^4 + ⋯ + ? ^?2.  Write a program in C++ that takes as input a positive integer n and computes the following productsum...
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.
python code Write a simple calculator: This program must have 9 functions: •main() Controls the flow...
python code Write a simple calculator: This program must have 9 functions: •main() Controls the flow of the program (calls the other modules) •userInput() Asks the user to enter two numbers •add() Accepts two numbers, returns the sum •subtract() Accepts two numbers, returns the difference of the first number minus the second number •multiply() Accepts two numbers, returns the product •divide() Accepts two numbers, returns the quotient of the first number divided by the second number •modulo() Accepts two numbers,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT