CodeBlanks Logo Icon CodeBlanks

Project design

Design the skeleton of the intermediate final mini app.

Project: Task manager

In this 5-lesson project you will build a task manager. Each lesson adds one piece, and by the final lesson you will have a program that combines OOP, templates, STL and file I/O.

You will use what you learned in previous groups: classes, templates, vectors and file streams. The first lesson defines a Task class: it holds a title and a done flag. The following lessons add a template function, an STL layer and file saving on top of this class. Each lesson's starting code contains the previous lesson's solution.

Task class skeleton

First we define the Task class. title is a string and done is a bool. The constructor takes the title and sets done to false.

Example: Task(std::string t) : title(t), done(false) {}. Here the member initializer list sets title from the parameter and done directly to false. When you create a task it is not yet done. In main you write Task t("Homework"); to create it. t.done starts as false which is 0.

Practice Define the Task class and print it

Define a class named Task. public members: std::string title, bool done. Constructor: Task(std::string t) : title(t), done(false) {}. In main create Task t("Homework"); and print t.title and t.done separated by a space with std::cout.

Starter code

main.cpp
#include <iostream>
#include <string>

// Define the Task class

int main() {
    // Create a Task instance and print it
    return 0;
}

Sample solution

main.cpp
#include <iostream>
#include <string>

class Task {
public:
    std::string title;
    bool done;
    Task(std::string t) : title(t), done(false) {}
};

int main() {
    Task t("Homework");
    std::cout << t.title << " " << t.done;
    return 0;
}

Expected output

Homework 0

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which two members should the Task class contain?

main.cpp
class Task {
    std::string title;
    bool done;
};
  • Color and size
  • Price and stock
  • Title and done flag Correct answer
  • Date and time

Explanation: Task contains title and done members.

2 Constructor initializer list

Question
Task(std::string t) : title(t), done(____) {}
Answer
Task(std::string t) : title(t), done(false) {}

Explanation: A new task starts with done=false.

3 Match each piece to its role

Term Meaning
class Task Class definition
std::string title Title member
bool done Done flag
Task(std::string t) Constructor

All lessons in Intermediate