According to Wikipedia: “The International Collegiate Programming Contest, known as the ICPC, is an annual multi-tiered competitive programming competition among the universities of the world.” Moreover, the participants of the contest should be no older than 24. Complete the following function which takes as input two parameters: the current year and the birth year of a student. The function should return the age of the person given the parameters. int calculateAge(int current_year, int birth_year) { part b) The teacher wants to determine if a group of students is eligible for this competition. Complete the following piece of code considering that the age of these students are stored in the studentsAge array and use the calculateAge function to determine the eligibility. Note: solution should use calculateAge !
in C++ program please:
part a)
According to Wikipedia: “The International Collegiate
Complete the following function which takes as input two parameters: the current year and the birth year of a student. The function should return the age of the person given the parameters.
int calculateAge(int current_year, int birth_year) {
part b)
The teacher wants to determine if a group of students is eligible for this competition. Complete the following piece of code considering that the age of these students are stored in the studentsAge array and use the calculateAge function to determine the eligibility.
Note: solution should use calculateAge !
int main() { int studentsAge[10];
#your answer
for (int i = 0; i < 10; i++) { cin >> studentsAge[i];
# your answer
Your program should print “The students are eligible” or “The students are not eligible” once it is run.
Hint : in part b , in the statement `cin >> studentsAge[i];`, the input which stored in the array `studentsAge` should be the students' birth year.
#include <iostream>
using namespace std;
int calculateAge(int current_year, int birth_year) {
return current_year - birth_year;
}
int main(){
int studentsAge[10];
for (int i = 0; i < 10; i++) {
cin >> studentsAge[i];
}
int maxAge = 24;
time_t current_time;
current_time = time(NULL);
int current_year;
current_year = 1970 + current_time / 31537970;
for(int i=0;i<10;i++){
if(calculateAge(current_year, studentsAge[i])<25){
cout<<"The students are eligible\n";
}
else{
cout<<"The students are not eligible\n";
}
}
return 0;
}
Step by step
Solved in 2 steps with 1 images