Menu
Coddy logo textTech

Viewing Tasks

Part of the Logic & Flow section of Coddy's C++ journey — lesson 20 of 56.

challenge icon

Challenge

Easy

Extend your task list tool by implementing the view functionality to display all tasks in a numbered list format. This builds on the previous lesson by adding the ability to see what tasks have been stored in the system.

The following inputs will be provided:

  • An integer n representing the number of tasks to add to the list
  • Then n strings representing the task descriptions

Your program should:

  1. Start with the same setup from the previous lesson (empty std::vector<std::string> named tasks and welcome message)
  2. Read the number of tasks and add each task description to the vector using push_back()
  3. Check if the tasks vector is empty using the .empty() method
  4. If the vector is empty, print a message indicating there are no tasks
  5. If the vector contains tasks, iterate through it using a traditional for loop with an index
  6. Print each task as a numbered list, starting from 1 (not 0)
  7. Display the total number of tasks at the end

Use the following exact output format:

For empty task list:

Welcome to Task List Tool!

Menu Options:
1. Add Task
2. View Tasks
3. Quit

Task list system initialized and ready!
No tasks available.

For non-empty task list:

Welcome to Task List Tool!

Menu Options:
1. Add Task
2. View Tasks
3. Quit

Task list system initialized and ready!
Your Tasks:
1. [first task]
2. [second task]
3. [third task]
...
Total tasks: [number of tasks]

Use a traditional for loop with i starting from 0 and going to tasks.size(). When printing, display i + 1 to show task numbers starting from 1, and access each task using tasks[i].

Try it yourself

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    vector<string> tasks;
    
    cout << "Welcome to Task List Tool!" << endl;
    cout << endl;
    cout << "Menu Options:" << endl;
    cout << "1. Add Task" << endl;
    cout << "2. View Tasks" << endl;
    cout << "3. Quit" << endl;
    cout << endl;
    cout << "Task list system initialized and ready!" << endl;
    
    string taskDescription;
    getline(cin, taskDescription);
    
    tasks.push_back(taskDescription);
    
    cout << "Task \"" << taskDescription << "\" added successfully!" << endl;
    cout << "Total tasks: " << tasks.size() << endl;
    
    return 0;
}

All lessons in Logic & Flow