Build a Basic Car Class

Hard Introduction to C++ Classes & Objects PRO
🔒 Login to Unlock

Problem Statement

Build a `Car` class with public attributes `std::string brand`, `std::string model`, and `int year`. Add a public method `void displayInfo()` that prints “Brand: [brand]”, “Model: [model]”, and “Year: [year]” on separate lines. Read these three inputs, instantiate the object, and call the method.

Input Format

Two single-word strings and an integer separated by spaces.

Output Format

Print the formatted details separated by line breaks.

Constraints

Strings will not contain spaces.

Sample Input

Toyota Corolla 2020

Sample Output

Brand: Toyota
Model: Corolla
Year: 2020

Explanation

This brings everything together: defining attributes, linking member functions, taking standard input, and managing object behavior.

Starter Code

#include <iostream>
#include <string>

class Car {
public:
    // Define attributes and displayInfo() here
};

int main() {
    // Instantiate Car, read input, assign attributes, and display
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used