Saturday, 12 November 2016

Write a program that uses a structure to store these three parts of a phone number separately. Call the structure phone. Create two structure variables of type phone. Initialize one, and have the user input a number for the other one. Then display both numbers.

Assigment #2 Q#6

Write a program that uses a structure to store these three parts of a phone number separately. Call the structure phone. Create two structure variables of type phone. Initialize one, and have the user input a number for the other one. Then display both numbers.
#include<iostream>
#include<string>
using namespace std;

struct P_No { // Struct to store the number
       int Area_c;
       int ex_c;
       int no;
};
void GetsAndDisply(P_No &, P_No &); //gets the number and display it
void Sterics();

int main()
{
       P_No p, p1; //creating instance
       GetsAndDisply(p, p1); //calling of a function to get and display the number
       return 0;
}
void GetsAndDisply(P_No &phn, P_No &m) //function to get the number and display it
{
       Sterics(); //Calling of a function to print the steric
       cout << "*\tEnter your area code, exchange, and number: ";
       cin >> phn.Area_c >> phn.ex_c >> phn.no; //takes the number from the user
       if ((phn.Area_c > 10 || phn.Area_c <= 99) && (phn.ex_c > 99 || phn.ex_c < 999) && (phn.no >999 || phn.no <= 9999))
       {
              m.Area_c = 051; m.ex_c = 413; m.no = 1212;
              cout << endl << "*\t\tMy Number is : 0" << phn.Area_c << " " << phn.ex_c << " " << phn.no << endl << endl;

              cout << "*\t\tYour Number is : 0" <<phn.Area_c<< " " << phn.ex_c << " " << phn.no << endl << endl;
              m.Area_c = 051; m.ex_c = 413; m.no = 1212;
       }
       else
              cout << "*\t\tInvalidOutput" << endl;

       Sterics(); //Calling of a function to print the steric
}
void Sterics() //Function to print the sterics
{
       for (int k = 1; k < 37; k++)
       {
              cout << "**";
       }
       cout << endl;

}

1 comment:

  1. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. Ben Luker Australia

    ReplyDelete