📜  错误追踪系统

📅  最后修改于: 2021-05-28 04:54:54             🧑  作者: Mango

什么是错误跟踪系统?错误跟踪系统是一种跟踪用户在任何软件开发或任何项目中遇到的错误的软件。

错误跟踪系统的三个主要功能是:

  1. 创建一个新的文本文件,并将用户输入的详细信息写入文本文件。
  2. 更改错误状态的选项。
  3. 特定错误文件的报告。

现在将看到涉及的功能

驱动程序函数:想法是保留一个变量ID ,该变量ID可以存储到现在为止已注册的Bug的ID。用户主要可以从三个选项中选择功能:

  1. 创建新的错误
  2. 错误的变更状态
  3. 报告错误
  4. 出口

切换语句用于切换到用户喜欢的功能。

创建一个新的Bug:此函数将询问用户他的名字,并创建一个新的文本文件作为名称并附加ID号。

例如:

  • 如果用户第一次创建错误文件,该错误文件的ID最初为0,并且最初以0递增1,并且用户输入名称作为错误文件,那么我们程序将创建的文件将被命名为bugfile1.txt。
  • 如果用户创建了1个三次,增加了第三次ID的错误文件,如果用户输入名称作为bugfile又那么该文件,我们的程序将创建将被命名为bugfile3.txt

命名文件后,从用户处获取信息,并将其添加到文本文件中,并附带创建时间

用户针对错误所采取的信息是:

  1. 用户提交的错误。
  2. 错误类型
  3. 错误优先级
  4. 错误说明
  5. 错误状态

更改错误的状态:获取有关错误的信息,然后在所需的文件中更改错误的状态。另外,更新错误的上次更新时间。

报告错误:获取有关错误的信息。如Bug文件名和打印Bug的内容。

以下是错误跟踪系统的实现:

Diver Function
// C program for the Driver Function
// of the Bug Tracking System
 
#include 
 
// Driver Code
void main()
{
    printf("***************");
    printf("BUG TRACKING SYSTEM");
    printf("***************\n");
 
    int number, i = 1;
 
    // Id initialised to 0
    int id = 0;
 
    // while loop to run
    while (i != 0) {
        printf("\n1. FILE A NEW BUG\n");
        printf("2. CHANGE THE STATUS OF THE BUG\n");
        printf("3. GET BUG REPORT\n4. EXIT");
        printf("\n\n ENTER YOUR CHOICE:");
 
        scanf("%d", &number);
 
        // Using switch to go case by case
        switch (number) {
        case 1:
            id++;
 
            // Creating a New Bug
            filebug(id);
            break;
        case 2:
 
            // Change Status of Bug
            changestatus();
            break;
        case 3:
 
            // Report the Bug
            report();
            break;
        case 4:
            i = 0;
            break;
        default:
            printf("\ninvalid entry");
            break;
        }
    }
}


Create a Bug
// C program for filing a bug
// in Bug Tracking System
 
#include 
#include 
#include 
#include 
#include 
 
// Function to file the Bug into
// the Bug Tracking System
void filebug(int id)
{
    printf("**********");
    printf("FILING A BUG");
    printf("***********\n");
 
    // Current Time
    time_t CurrentTime;
    time(&CurrentTime);
 
    char name[20], bugtype[50];
    char bugdescription[1000];
    char bugpriority[30];
    int bugstatus;
 
    FILE* ptr;
 
    // User name
    printf("Enter your name:\n");
    scanf("%s", name);
    char ids[10];
    itoa(id, ids, 10);
    strcat(name, ids);
    char ex[] = ".txt";
    strcat(name, ex);
 
    // Filename of the Bug
    printf("Filename :%s\n", name);
    ptr = fopen(name, "w");
 
    // Case when file cannot be created
    if (ptr == NULL)
        printf("cannot create file!!!\n");
 
    fprintf(ptr, "DATE AND TIME : %s",
            ctime(&CurrentTime));
 
    // ID in the Text File
    fprintf(ptr, "BUG ID    :    %d\n", id);
 
    // Adding New Line in Text File
    fprintf(ptr, "\n");
 
    // Bug ID
    printf("BUG ID:%d\n", id);
 
    fprintf(ptr, "BUG FILED BY: %s\n",
            name);
    fprintf(ptr, "\n");
 
    printf("Enter bug type:\n");
    scanf(" %[^\n]", bugtype);
 
    // Bug Type
    fprintf(ptr, "TYPE OF BUG: %s",
            bugtype);
    fprintf(ptr, "\n");
 
    // Bug Priority
    printf("Enter bug priority:\n");
    scanf(" %[^\n]s", bugpriority);
 
    fprintf(ptr, "BUG PRIORITY: %s\n",
            bugpriority);
    fprintf(ptr, "\n");
 
    // Bug Description
    printf("Enter the bug description:\n");
    scanf(" %[^\n]s", bugdescription);
 
    fprintf(ptr, "BUG DESCRIPTION: %s\n",
            bugdescription);
    fprintf(ptr, "\n");
 
    printf("Status of bug:\n");
    printf("1. NOT YET ASSIGNED\n");
    printf("2.IN PROCESS\n 3.FIXED\n");
    printf("4.DELIVERED\n ENTER YOUR CHOICE:");
 
    int j;
    scanf("%d", &j);
 
    // Date and time of Bug Creation
    fprintf(ptr, "DATE AND TIME: %s",
            ctime(&CurrentTime));
 
    fprintf(ptr, "BUG STATUS:");
 
    // Switching for the Status of the
    // Bug
    switch (j) {
    case 1:
        fprintf(ptr, "NOT YET ASSIGNED\n");
        break;
    case 2:
        fprintf(ptr, "IN PROCESS\n");
        break;
    case 3:
        fprintf(ptr, "FIXED\n");
        break;
    case 4:
        fprintf(ptr, "DELIVERED\n");
        break;
    default:
        printf("invalid choice\n");
        break;
    }
 
    fclose(ptr);
}


Status of Bug
// C program for changing Status
// in Bug Tracking System
 
#include 
#include 
#include 
#include 
#include 
 
// Function to Change the status
// of the Bug
void changestatus()
{
    printf("*************");
    printf("Change status");
    printf("**************\n");
 
    // Current Time
    time_t CurrentTime;
    time(&CurrentTime);
 
    FILE* file;
    char name[50];
 
    // Bug File name
    printf("Enter file name:\n");
    scanf("%s", name);
    char ex[] = ".txt";
    strcat(name, ex);
 
    // Opening the Bug in Append Mode
    file = fopen(name, "a");
 
    printf("\n 1. NOT YET ASSIGNED\n");
    printf(" 2.IN PROCESS\n 3.FIXED\n");
    printf(" 4.DELIVERED\n ENTER YOUR CHOICE:");
 
    // Change the Status
    int k;
    scanf("%d", &k);
 
    fprintf(file, "\n");
    fprintf(file, "DATE AND TIME : %s",
            ctime(&CurrentTime));
 
    fprintf(file, "BUG STATUS:");
 
    // Changing the status on the
    // basis of the user input
    switch (k) {
    case 1:
        fprintf(file, "NOT YET ASSIGNED\n");
        break;
    case 2:
        fprintf(file, "IN PROCESS\n");
        break;
    case 3:
        fprintf(file, "FIXED\n");
        break;
    case 4:
        fprintf(file, "DELIVERED\n");
        break;
    default:
        printf("invalid choice\n");
        break;
    }
    fclose(file);
}


Report Bug
// C program for report a bug
// in Bug Tracking System
 
#include 
#include 
#include 
#include 
#include 
 
// Function to report the Bug
// in the Bug Tracking System
void report()
{
    printf("**********");
    printf("REPORT");
    printf("**********\n");
 
    FILE* fp;
    char name[50];
 
    // Asking the Filename to report
    // the bug of the file
    printf("Enter file name:\n");
    scanf("%s", name);
    char ex[] = ".txt";
    strcat(name, ex);
 
    // Opening the file into the
    // Read mode
    fp = fopen(name, "r");
 
    char ch;
    ch = getc(fp);
 
    // Character of the File
    while (ch != EOF) {
        printf("%c", ch);
        ch = getc(fp);
    }
 
    fclose(fp);
    getch();
}


Complete Code
// C program for the
// Bug Tracking System
 
#include 
#include 
#include 
#include 
#include 
 
// Function to file the Bug into
// the Bug Tracking System
void filebug(int id)
{
    printf("**********");
    printf("FILING A BUG");
    printf("***********\n");
 
    // Current Time
    time_t CurrentTime;
    time(&CurrentTime);
 
    char name[20], bugtype[50];
    char bugdescription[1000];
    char bugpriority[30];
    int bugstatus;
 
    FILE* ptr;
 
    // User name
    printf("Enter your name:\n");
    scanf("%s", name);
    char ids[10];
    itoa(id, ids, 10);
    strcat(name, ids);
    char ex[] = ".txt";
    strcat(name, ex);
 
    // Filename of the Bug
    printf("Filename :%s\n", name);
    ptr = fopen(name, "w");
 
    // Case when file cannot be created
    if (ptr == NULL)
        printf("cannot create file!!!\n");
 
    fprintf(ptr, "DATE AND TIME : %s",
            ctime(&CurrentTime));
 
    // ID in the Text File
    fprintf(ptr, "BUG ID    :    %d\n", id);
 
    // Adding New Line in Text File
    fprintf(ptr, "\n");
 
    // Bug ID
    printf("BUG ID:%d\n", id);
 
    fprintf(ptr, "BUG FILED BY: %s\n",
            name);
    fprintf(ptr, "\n");
 
    printf("Enter bug type:\n");
    scanf(" %[^\n]", bugtype);
 
    // Bug Type
    fprintf(ptr, "TYPE OF BUG: %s",
            bugtype);
    fprintf(ptr, "\n");
 
    // Bug Priority
    printf("Enter bug priority:\n");
    scanf(" %[^\n]s", bugpriority);
 
    fprintf(ptr, "BUG PRIORITY: %s\n",
            bugpriority);
    fprintf(ptr, "\n");
 
    // Bug Description
    printf("Enter the bug description:\n");
    scanf(" %[^\n]s", bugdescription);
 
    fprintf(ptr, "BUG DESCRIPTION: %s\n",
            bugdescription);
    fprintf(ptr, "\n");
 
    printf("Status of bug:\n");
    printf("1. NOT YET ASSIGNED\n");
    printf("2.IN PROCESS\n 3.FIXED\n");
    printf("4.DELIVERED\n ENTER YOUR CHOICE:");
 
    int j;
    scanf("%d", &j);
 
    // Date and time of Bug Creation
    fprintf(ptr, "DATE AND TIME: %s",
            ctime(&CurrentTime));
 
    fprintf(ptr, "BUG STATUS:");
 
    // Switching for the Status of the
    // Bug
    switch (j) {
    case 1:
        fprintf(ptr, "NOT YET ASSIGNED\n");
        break;
    case 2:
        fprintf(ptr, "IN PROCESS\n");
        break;
    case 3:
        fprintf(ptr, "FIXED\n");
        break;
    case 4:
        fprintf(ptr, "DELIVERED\n");
        break;
    default:
        printf("invalid choice\n");
        break;
    }
 
    fclose(ptr);
}
 
// Function to Change the status
// of the Bug
void changestatus()
{
    printf("*************");
    printf("Change status");
    printf("**************\n");
 
    // Current Time
    time_t CurrentTime;
    time(&CurrentTime);
 
    FILE* file;
    char name[50];
 
    // Bug File name
    printf("Enter file name:\n");
    scanf("%s", name);
    char ex[] = ".txt";
    strcat(name, ex);
 
    // Opening the Bug in Append Mode
    file = fopen(name, "a");
 
    printf("\n 1. NOT YET ASSIGNED\n");
    printf(" 2.IN PROCESS\n 3.FIXED\n");
    printf(" 4.DELIVERED\n ENTER YOUR CHOICE:");
 
    // Change the Status
    int k;
    scanf("%d", &k);
 
    fprintf(file, "\n");
    fprintf(file, "DATE AND TIME : %s",
            ctime(&CurrentTime));
 
    fprintf(file, "BUG STATUS:");
 
    // Changing the status on the
    // basis of the user input
    switch (k) {
    case 1:
        fprintf(file, "NOT YET ASSIGNED\n");
        break;
    case 2:
        fprintf(file, "IN PROCESS\n");
        break;
    case 3:
        fprintf(file, "FIXED\n");
        break;
    case 4:
        fprintf(file, "DELIVERED\n");
        break;
    default:
        printf("invalid choice\n");
        break;
    }
    fclose(file);
}
 
// Function to report the Bug
// in the Bug Tracking System
void report()
{
    printf("**********");
    printf("REPORT");
    printf("**********\n");
 
    FILE* fp;
    char name[50];
 
    // Asking the Filename to report
    // the bug of the file
    printf("Enter file name:\n");
    scanf("%s", name);
    char ex[] = ".txt";
    strcat(name, ex);
 
    // Opening the file into the
    // Read mode
    fp = fopen(name, "r");
 
    char ch;
    ch = getc(fp);
 
    // Character of the File
    while (ch != EOF) {
        printf("%c", ch);
        ch = getc(fp);
    }
 
    fclose(fp);
    getch();
}
 
// Driver Code
void main()
{
    printf("***************");
    printf("BUG TRACKING SYSTEM");
    printf("***************\n");
 
    int number, i = 1;
 
    // Id initialised to 0
    int id = 0;
 
    // while loop to run
    while (i != 0) {
        printf("\n1. FILE A NEW BUG\n");
        printf("2. CHANGE THE STATUS OF THE BUG\n");
        printf("3. GET BUG REPORT\n4. EXIT");
        printf("\n\n ENTER YOUR CHOICE:");
 
        scanf("%d", &number);
 
        // Using switch to go case by case
        switch (number) {
        case 1:
            id++;
 
            // Creating a New Bug
            filebug(id);
            break;
        case 2:
 
            // Change Status of Bug
            changestatus();
            break;
        case 3:
 
            // Report the Bug
            report();
            break;
        case 4:
            i = 0;
            break;
        default:
            printf("\ninvalid entry");
            break;
        }
    }
}


输出:

驱动函数:

创建错误:

更改状态并报告错误

错误档案:

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。