Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Solve these in C++. 1. Write a method or function that accepts an argument for t

ID: 3662591 • Letter: S

Question

Solve these in C++.

1. Write a method or function that accepts an argument for the age of an individual and returns the year that person was born.

2. Write a method of function that accepts an integer argument. The method should use “if-else” statements to determine if the integer is between 45 and 55.

3. Write a method or function that accepts an argument for a person’s name. The method should loop through the number of characters in the name sending each character to the screen each on a separate line.

Explanation / Answer

Write a method or function that accepts an argument for the age of an individual and returns the year that person was born.

1. Solution for Method 1:
int year(int age)
{
// This value is change according to user input range
int range_of_years = 2000;
int year = range_of_years - age;
return year;

}

2. Write a method of function that accepts an integer argument. The method should use “if-else” statements to determine if the integer is between 45 and 55.

Solution for Method 2:
void range_check(int arg)
{
   if(45 < arg && arg <55)
   {
       cout<<"Arg is with in the 45 to 55"<<endl;
   }
   else
   {
       cout<<"Arg is not with in the range"<<endl;
   }
}

3. Write a method or function that accepts an argument for a person’s name. The method should loop through the number of characters in the name sending each character
to the screen each on a separate line.

Solution for the Method 3:
void screen_display(char name[])
{
int i=0;
for(i=0;name[i]!='';i++)
cout<<name[i]<<" "<<endl;

}