Knowee
Questions
Features
Study Tools

Write a program in C++ that takes age of five persons and then just display the age of each person usingarrays

Question

Write a program in C++ that takes age of five persons and then just display the age of each person usingarrays

🧐 Not the exact question you are looking for?Go ask a question

Solution

Claro, aquí tienes un programa que toma la edad de cinco personas y luego muestra la edad de cada una usando arreglos:

#include <iostream>
using namespace std;

int main() {
    const int numPersons = 5;
    int ages[numPersons];

    // Tomar la edad de cinco personas
    for (int i = 0; i < numPersons; ++i) {
        cout << "Ingrese la edad de la persona " << i + 1 << ": ";
        cin >> ages[i];
    }

    // Mostrar la edad de cada persona
    cout << "\nLas edades ingresadas son:\n";
    for (int i = 0; i < numPersons; ++i) {
        cout << "Persona " << i + 1 << ": " << ages[i] << " años" << endl;
    }

    return 0;
}

Este programa primero declara un arreglo de enteros para almacenar las edades de cinco personas. Luego, utiliza un bucle for para solicitar al usuario que ingrese la edad de cada persona y las almacena en el arreglo. Finalmente, otro bucle for se utiliza para mostrar las edades almacenadas.

This problem has been solved

Similar Questions

Write a program in C++ that takes age of five persons and then just display the age of each person usingarrays

Could not pasteHailey is curious about the ages of her friends, Alex and Bob. She knows the sum of their ages and wants to determine their individual ages. The hint is that Alex is 5 years older than Bob. Can you help her create a program using pointers that calculates and prints the ages of Alex and Bob? Input format : The input consists of an integer N, representing the sum of Alex and Bob's ages. Output format : The first line of output prints the age of Alex. The second line prints the age of Bob. Refer to the sample output for formatting specifications. Code constraints : 1 ≤ N ≤ 100 Sample test cases : Input 1 : 45 Output 1 : Alex is 25 years old. Bob is 20 years old. Input 2 : 91 Output 2 : Alex is 48 years old. Bob is 43 years old.

Imagine you are a teacher in a programming class, and you want to create a simple program to manage and analyze the scores of your students. Your task is to develop a C program that performs basic operations on an array representing the students' scores. The program will help you quickly view, analyze, and update the scores. Here's a breakdown of the tasks:1. Initialize Array:o Declare an array named studentScores to store the scores of 5 students in your programming class.o Initialize the array with random scores between 50 and 100 to represent their performance in a recent assignment.2. Display Scores:o Implement a function named displayScores that takes the array of scores and its size as parameters. This function should display the scores of each student, allowing you to easily check the performance distribution in the class.3. Calculate Average:o Implement a function named calculateAverage to calculate and return the average score of the students. This will help you understand the overall performance of the class.4. Find Highest Score:o Implement a function named findMaxScore that finds and returns the highest score in the array. Knowing the highest score will give you an idea of the best-performing student.5. Update Scores:o Implement a function named updateScores to increment each student's score by 5. This simulates a bonus or extra credit being added to the assignment.6. Main Function:o In the main function, initialize the array with scores, display the initial scores, calculate and display the average, find and display the highest score, update the scores, and finally, display the updated scores.

Single File Programming QuestionProblem StatementA school administrator needs to display the information of a student. The student has an ID (an integer) of 15, an age (an integer) of 23 and achieved a grade (a character) 'B'. Write a C program to print these details using appropriate data types and formatting.Input format :No console input.Output format :The output displays the values in the below format:Student id: 15Student age: 23Student grade: BRefer to the sample output for the formatting specification

Single File Programming QuestionProblem StatementIn a theme park, only people who meet specific criteria can experience the thrill of the roller coaster. Develop a program that takes age and height as inputs, determining eligibility using logical operators. If the age is 18 or older and the height is 150 cm or taller, output "Allowed!" Otherwise, output "Sorry, Not allowed."Input format :The first line of input consists of an integer, which represents the person's age.The second line of input consists of an integer, which represents the person's height (in cm).Output format :The output displays either "Allowed!" or "Sorry, Not allowed" based on the given conditions.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:6 ≤ age ≤ 10050 ≤ height ≤ 200Sample test cases :Input 1 :28151Output 1 :Allowed!Input 2 :17151Output 2 :Sorry, Not allowedInput 3 :6200Output 3 :Sorry, Not allowedInput 4 :18150Output 4 :Allowed!

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.