Answer to Question #199840 in C++ for Big boss

Question #199840

a) What is control structure? Explain it’s classification.

 b) And write a code for calculating age of a person.

c) Which control structure has used in this code.


1
Expert's answer
2021-05-28T00:21:45-0400
a) What is control structure? Explain it’s classification.
C++ has three kinds of control structures such as: the selection statements (if, if...else and switch), the sequence statement, and the repetition statements (while, for and do...while). 


-	Selection(branching) - is used to execute different statements depending on certain conditions.
-	Sequence - is a series of statements that execute one after another.
-	Repetition(loop or iteration) -  is used to repeat statements while certain conditions are met.


b) And write a code for calculating age of a person.

#include <iostream> 
#include <string>


using namespace std;




int main (){
	//aray of days in months
	int month[] = { 31, 28, 31, 30, 31, 30, 31,
		31, 30, 31, 30, 31 };

	int dayNow;
	int monthNow;
	int yearNow;
	//get the current date
	cout<<"Enter the current day: ";
	cin>>dayNow;
	cout<<"Enter the current month: ";
	cin>>monthNow;
	cout<<"Enter the current year: ";
	cin>>yearNow;


	int personBirthDay;
	int personBirthMonth;
	int personBirthYear;
	//get the person birthdate
	cout<<"Enter the person birth day: ";
	cin>>personBirthDay;
	cout<<"Enter the person birth month: ";
	cin>>personBirthMonth;
	cout<<"Enter the person birth year: ";
	cin>>personBirthYear;


	if (personBirthDay > dayNow) {
		dayNow = dayNow + month[personBirthMonth - 1];
		monthNow = monthNow - 1;
	}
	if (personBirthMonth > monthNow) {
		yearNow = yearNow - 1;
		monthNow = monthNow + 12;
	}
	//calculate age
	int ageDays = dayNow - personBirthDay;
	int ageMonths = monthNow - personBirthMonth;
	int ageYears = yearNow - personBirthYear;


	//display age
	cout<<"The age of the person is: "<<ageYears<<" year(s), "<<ageMonths<<" month(s),"<<ageDays<<" day(s).\n\n";


	//delay
	system("pause");
	return 0;
}

c) Which control structure has used in this code.
I have used Selection(branching) control structure to create this program.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
28.05.21, 09:57

Dear Bigboss,

You're welcome. We are glad to be helpful. 

If you liked our service please press like-button beside answer field. Thank you!



Bigboss
28.05.21, 07:27

May god bless u..Thanks a lot

Leave a comment

LATEST TUTORIALS
New on Blog