Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,488 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,846 people online right now. Registration is fast and FREE... Join Now!




Code Optimization

 
Reply to this topicStart new topic

Code Optimization, Video Rental for Turbo C

Bishounen
post 27 Sep, 2006 - 08:17 PM
Post #1


New D.I.C Head

*
Joined: 24 Sep, 2006
Posts: 2


My Contributions


hi guys! Im a beginner here in turbo c. could you give me some idea in this program.
i know how to search smile.gif but the rest is ques.gif . will you please help me.
here is the problem:
A program that allows the user to add, edit, and search customer record. Each customer record includes customer ID, gender, age, quantity, amount, and the total amount.
User is offlineProfile CardPM

Go to the top of the page


chakir
post 12 Oct, 2006 - 07:26 PM
Post #2


New D.I.C Head

*
Joined: 12 Oct, 2006
Posts: 1


My Contributions


can you posted the code for me please
User is offlineProfile CardPM

Go to the top of the page

Bishounen
post 12 Oct, 2006 - 08:04 PM
Post #3


New D.I.C Head

*
Joined: 24 Sep, 2006
Posts: 2


My Contributions


here's some code that i made. It is a simple Video Rental System. Can you please tell your suggestions, or help me in enhancing this code. sleepy.gif
It is a module program that can add customers, edit, search or delete customers.

CODE

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 100
main()
{
    int IDnum[size];
    int age[size];
    char gender[size];
    int quantity[size];
    float amount[size];
    float totalAmount[size];
    int ID;
    int ctr=0;
    int ctr2=0;
    int edit;
    char choice;
    char over;
    int add;
    int delete;
    int search;
    int not = 0;
    textmode(C40);
    textbackground(LIGHTBLUE);


main:        clrscr();
        textcolor(BLINK+LIGHTGREEN);
        gotoxy(5,3);
        cprintf("ß ß ß  VIDEO RENTAL SYSTEM  ß ß ß");
        gotoxy(17,6);
        textcolor(YELLOW);
        cprintf("[A]-Add");
        gotoxy(17,8);
        cprintf("[S]-Search");
        gotoxy(17,10);
        cprintf("[E]-Edit");
        gotoxy(17,12);
        cprintf("[D]-Delete");
        gotoxy(17,14);
        cprintf("[Q]-Quit");

        gotoxy(3,18);
        cprintf("Enter choice: ");
              choice=getche();


    switch(choice)
    {
        case 'a':
        case 'A':
        clrscr();
        do{
        gotoxy(3,12);
        cprintf("How many customers?: ");
        scanf("%d",&add);
        }while(add<0);
        ctr2=0;
        while(ctr2<add)
        {
        clrscr();
        gotoxy(3,5);
    ID:    cprintf("\nEnter ID number: ");
        scanf("%d",&ID);
        if(ID == IDnum[ctr2])
        {
         clrscr();
         goto ID;
        }
        IDnum[ctr] = ID;

        do{
        gotoxy(3,7);
        cprintf("Enter Gender: ");
        gender[ctr]=getche();
        }while(gender[ctr] !='m' && gender[ctr] !='M' && gender[ctr] != 'f' && gender[ctr] !='F');
        do{
        gotoxy(3,9);
        cprintf("Enter Age: ");
        scanf("%d",&age[ctr]);
        }while(age[ctr] <= 0);
        gotoxy(3,11);
        do{
        cprintf("How many rented items?: ");
        scanf("%d",&quantity[ctr]);
        gotoxy(3,13);
        }while(quantity[ctr] < 0);
        cprintf("How much each?: ");
        scanf("%f",&amount[ctr]);
        totalAmount[ctr]=quantity[ctr]*amount[ctr];
        gotoxy(3,15);
        cprintf("The total amount is: %f",totalAmount[ctr]);
        ctr++;
        ctr2++;
        }while(ctr2<add);
        textcolor(LIGHTGREEN+BLINK);
        gotoxy(3,17);
        cprintf("File added to memory...");
        gotoxy(5,20);
        system("pause");

    break;


        case 's':
        case 'S':
        clrscr();
        not = 1;

        gotoxy(3,12);
        cprintf("What ID you want to search?: ");
        scanf("%d",&search);
        clrscr();
        for(ctr2=0;ctr2<size;ctr2++)
        {
            if( search == IDnum[ctr2])
            {
            gotoxy(5,4);
            textcolor(LIGHTGREEN+BLINK);
            cprintf("ß ß ß Customers information ß ß ß");
            gotoxy(5,7);
            printf("ID number: %d",IDnum[ctr2]);
            gotoxy(5,9);
            printf("Gender: %c",gender[ctr2]);
            gotoxy(5,11);
            printf("Age: %d",age[ctr2]);
            gotoxy(5,13);
            printf("Items rented: %d",quantity[ctr2]);
            gotoxy(5,15);
            printf("Rent amount: %f",amount[ctr2]);
            gotoxy(5,17);
            printf("Total amount: %f",totalAmount[ctr2]);
            gotoxy(5,20);
            system("pause");
            goto main;
            }
            }
            if ( not == 0 );
            {
            textcolor(RED+BLINK);
            gotoxy(3,12);
            cprintf("File not found!");
            gotoxy(5,16);
            system("pause");
            }
            break;



        case 'e':
        case 'E':
        clrscr();

            gotoxy(1,12);
            cprintf("\nEnter ID number you want to edit: ");
            scanf("%d",&edit);
            clrscr();
            for(ctr2=0;ctr2<size;ctr2++)
            {
            if(edit==IDnum[ctr2])
            {
            gotoxy(3,5);
            cprintf("Enter new ID number: ");
            scanf("%d",&IDnum[ctr2]);
            do{
            gotoxy(3,7);
            cprintf("Enter Gender: ");
            gender[ctr2]=getche();
            }while(gender[ctr2] != 'm' && gender[ctr2] != 'M' && gender[ctr2] != 'f' && gender[ctr2] != 'F');
            gotoxy(3,9);
            do{
            cprintf("Enter Age: ");
            scanf("%d",&age[ctr2]);
            gotoxy(3,11);
            }while(age[ctr] <= 0);
            do{
            cprintf("How many rented items?: ");
            scanf("%d",&quantity[ctr2]);
            }while(quantity[ctr2] < 0);
            gotoxy(3,13);
            do{
            cprintf("How much each?: ");
            scanf("%f",&amount[ctr2]);
            }while(amount[ctr2] < 0);
            totalAmount[ctr2]=quantity[ctr2]*amount[ctr2];
            gotoxy(3,16);
            cprintf("The total amount is: %f",totalAmount[ctr2]);
            textcolor(LIGHTGREEN+BLINK);
            gotoxy(5,20);
            cprintf("File succesfully updated!");
            gotoxy(5,22);
            system("pause");
            goto main;
            }
            }
            if (not == 0);
            {
            textcolor(BLINK+RED);
            gotoxy(3,12);
            cprintf("File not found!");
            gotoxy(5,16);
            system("pause");
            goto main;
            }

        case 'd':
        case 'D':
        clrscr();

             gotoxy(3,12);
             cprintf("What file you want to delete: ");
             scanf("%d",&delete);
             clrscr();

             for(ctr2=0;ctr2<size;ctr2++)

                {
                  if ( delete == IDnum[ctr2])
                {
                    IDnum[ctr2]='0';
                    gender[ctr2]='0';
                    age[ctr2]='0';
                    quantity[ctr2]='0';
                    amount[ctr2]='0';
                    totalAmount[ctr2]='0';
                    textcolor(LIGHTGREEN+BLINK);
                    gotoxy(5,10);
                    cprintf("File Deleted!");
                    gotoxy(5,12);
                    system("pause");
                    goto main;
                }
                }
                if (not == 0);
                {
                textcolor(RED+BLINK);
                gotoxy(3,12);
                cprintf("File not found!");
                gotoxy(5,16);
                system("pause");
                goto main;
                }

        case 'q':
        case'Q':
        exit(0);


        default:
        cprintf("\a");
        clrscr();
        break;

    }

        goto main;

}
User is offlineProfile CardPM

Go to the top of the page

gregoryH
post 13 Oct, 2006 - 03:04 PM
Post #4


D.I.C Regular

Group Icon
Joined: 4 Oct, 2006
Posts: 417



Dream Kudos: 50
My Contributions


bis...

Code needs to be broken into a number of functions. and call those functions from the switch statement, that way you will be able to properly test each sub function ebfore integrating it
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 12:07AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month