C++: A profile card

Print a small profile card from three values.

What to build

A program that combines reading, calculating and fixed text.

Requirements

  • Read a first name, a last name and a birth year.
  • Print +---+.
  • Print Name: LAST, FIRST.
  • Print Age in 2030: A.
  • Print +---+ again.

Input

One line: first name, last name, birth year.

Output

Four lines.

Constraints

The birth year is from 1900 to 2030.

Example

Input:

Mitu Akter 2004

Output:

+---+
Name: Akter, Mitu
Age in 2030: 26
+---+

Why it works

Reading into separate variables means the values can be printed in any order, and calculations can use them freely.

Examples

Example 1 · Input
Mitu Akter 2004
Expected output
+---+
Name: Akter, Mitu
Age in 2030: 26
+---+
Example 2 · Input
Rahim Uddin 2000
Expected output
+---+
Name: Uddin, Rahim
Age in 2030: 30
+---+

Hints

Hint 1

Read three values in order: two words and a whole number.

Hint 2

Age is 2030 minus the birth year.

Hint 3

Text and values can alternate in one cout chain.

Solution

Show one correct solution (try it yourself first)
#include <iostream>
#include <string>
using namespace std;

int main() {
    string first, last;
    int year;
    cin >> first >> last >> year;
    cout << "+---+" << endl;
    cout << "Name: " << last << ", " << first << endl;
    cout << "Age in 2030: " << 2030 - year << endl;
    cout << "+---+" << endl;
    return 0;
}

Lesson: Your first C++ program →