Knowee
Questions
Features
Study Tools

Context: smart planner using array,function,switch case,loop in c programming language not using any thing else

Question

Context: smart planner using array,function,switch case,loop in c programming language not using any thing else

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

Solution

Sure, let's break down the steps to create a smart planner using arrays, functions, switch case, and loops.

Step 1: Define the Structure

First, define the structure of the planner. For simplicity, let's assume each task has a name and a status (e.g., pending or completed).

#include <stdio.h>
#include <string.h>

#define MAX_TASKS 100
#define MAX_NAME_LENGTH 50

typedef struct {
    char name[MAX_NAME_LENGTH];
    int status; // 0 for pending, 1 for completed
} Task;

Step 2: Initialize the Planner

Create an array to hold the tasks and a variable to keep track of the number of tasks.

Task planner[MAX_TASKS];
int taskCount = 0;

Step 3: Function to Add a Task

Write a function to add a new task to the planner.

void addTask(char name[]) {
    if (taskCount < MAX_TASKS) {
        strcpy(planner[taskCount].name, name);
        planner[taskCount].status = 0; // Task is pending by default
        taskCount++;
    } else {
        printf("Planner is full!\n");
    }
}

Step 4: Function to Mark a Task as Completed

Write a function to mark a task as completed.

void completeTask(int index) {
    if (index >= 0 && index < taskCount) {
        planner[index].status = 1;
    } else {
        printf("Invalid task index!\n");
    }
}

Step 5: Function to Display Tasks

Write a function to display all tasks.

void displayTasks() {
    for (int i = 0; i < taskCount; i++) {
        printf("Task %d: %s [%s]\n", i + 1, planner[i].name, planner[i].status ? "Completed" : "Pending");
    }
}

Step 6: Main Function with Switch Case

Use a switch case inside a loop to handle user input and perform actions.

int main() {
    int choice;
    char taskName[MAX_NAME_LENGTH];
    int taskIndex;

    while (1) {
        printf("\nSmart Planner\n");
        printf("1. Add Task\n");
        printf("2. Complete Task\n");
        printf("3. Display Tasks\n");
        printf("4. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                printf("Enter task name: ");
                scanf(" %[^\n]", taskName); // Read string with spaces
                addTask(taskName);
                break;
            case 2:
                printf("Enter task index to complete: ");
                scanf("%d", &taskIndex);
                completeTask(taskIndex - 1); // Convert to 0-based index
                break;
            case 3:
                displayTasks();
                break;
            case 4:
                return 0;
            default:
                printf("Invalid choice!\n");
        }
    }
}

Summary

  1. Define a Task structure.
  2. Initialize an array of tasks and a task count.
  3. Implement functions to add tasks, complete tasks, and display tasks.
  4. Use a loop and switch case in the main function to handle user input.

This is a basic implementation of a smart planner. You can expand it by adding more features like editing tasks, deleting tasks, or saving tasks to a file.

This problem has been solved

Similar Questions

make a ppt on smart planner using array,loops,function,switch case

how to write a code in c language to make smart planner

Context: make a ppt on smart planner using array,loops,function,switch case with an example and the whole ppt should be in english

write a code to make a smart planner

Objectives - Learn stacksUsing ArrayCreate a program to implement a stack by using array1) You have to get the user choice using keyboard as follows in the main functionChoices1. Push2. Pop3. Print all the elements of the stack4. Print the top element of the stack5. Exit2) Implement functions one by one according to each choice3) Using a switch case complete the code.Using Linked-listDo the above exercise using singly linked list

1/1

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.