In your program for HW4- Telephone Service Simulation, when is_valid_areacode() is being executed, which functions will have their activation frames in the stack? Support your answer by attaching a screenshot from the visual studio code
This is the code only for reference:
#include<bits/stdc++.h>
using namespace std;
int main()
{
//user input
cout<<"Enter the 10 digit phone number: ";
string phone_num;
cin >> phone_num;
//by using array<T make valid area code
string arr[] = {"405", "520", "550", "650", "620"};
// If the phone number is not of 10 digit
if (phone_num.length()!=10) //by using if else loop
cout << "Invalid phone number";
else{
int choice;
// Ask user for the choice of execution of program
cout << "Enter 1 for if else statement and 0 for switch case statements. ";
cin >> choice;
string area_code = phone_num.substr(0,3);
int area_cd = stoi(area_code);
if (choice == 1){
// use substr function to extract the first three digit
// Use of the find function to check if the code is valid
if (find(begin(arr),end(arr),area_code)!=end(arr)){
cout << "The area code is "<<area_code;
}
else{
cout << "Invalid area code"; //if user enter some other number
}
}
else{
// Convert into integer and use of switch cases
switch(area_cd){
case 405:
cout << "The area code is 405";
break;
case 520:
cout << "The area code is 520";
break;
case 550:
cout << "The area code is 550";
break;
case 650:
cout << "The area code is 650";
break;
case 620:
cout << "The area code is 620";
break;
default:
cout << "Invalid area code";
}
}
}
return 0;
}
ANSWER FOR THIS QUESTION ONLY
1. a) In your program for HW4- Telephone Service Simulation, when is_valid_areacode() is being executed, which functions will have their activation frames in the stack? Support your answer by attaching a screenshot from the visual studio code
Step by step
Solved in 3 steps