the 50 years old mom is back and need help again

This is a discussion on the 50 years old mom is back and need help again within the C Programming forums, part of the General Programming Boards category; HEy Guys, I need help again. This is my last assignmnet and the instructor told us to change all of ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    7

    the 50 years old mom is back and need help again

    HEy Guys, I need help again. This is my last assignmnet and the instructor told us to change all of this to C++.
    I have no idea on how to do this, so I need help/
    Please.......
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>  /*for toupper*/
    #include <string.h> /*needed for strcpy()*/
    
    #define MAX_NAME 30 
    #define TITLE "Mabuhay Video Store" 
    #define MAX_VIDEO 10 
    
    void getcustomer(char Fullname[],char Address[],char City[],
                     char CouponApplied[], char Y);
    
    void getVideos(char Fullname[],char CouponApplied[],char VideoTitle[][MAX_NAME + 1],
                   char Category[], int DaysRented[]);
    
    double computecharges(double charge, float price[], int DaysRented[], char Category[],char CouponApplied[], double Tax);
    
    void displayreceipt(char Fullname[],char Address[],char City[],
                        char VideoTitle[][MAX_NAME + 1],char Category[],
                        int DaysRented[],char CouponApplied[],
                        char Late[][5],float price[], char Y, double Tax, double charge);
    
    void initialise(char VideoTitle[][MAX_NAME + 1],char Category[],char Late[][5],
                    float price[],int DaysRented[]);
    
    
    int main(void) 
    { 
    
    char Fullname[MAX_NAME + 1]; 
    char Address[MAX_NAME + 1]; 
    char City[MAX_NAME + 1]; 
    char CouponApplied[4]; 
    	
    	int choice; 
    char Y = 'N'; 
    char VideoTitle[10][MAX_NAME + 1]; 
    char Category[10]; 
    int DaysRented[10]; 
    
    float price[10]; 
    char Late[10][5]; 
    double charge = 0.0; 
    double Tax = 0.0;
    
    
      do
      {
        system ("cls");
        printf("=============================\n");
        printf(" %s\n", TITLE);
        printf("=============================\n\n");
        printf("1 Enter Customer Information\n");
        printf("2 Enter Rental Information\n");
        printf("3 Compute Charges\n");
        printf("4 Display Receipt\n");
        printf("5 Exit Program\n\n");
        printf(" Selection: ");
        scanf("%d",&choice);
        getchar();
    
        if(choice==1)
        {
          /*intialise next customer*/
           initialise(VideoTitle,Category,Late,price,DaysRented);
           getcustomer(Fullname,Address,City,CouponApplied, Y);
        }
        else if(choice==2)
        {
          getVideos(Fullname,CouponApplied, VideoTitle,Category, DaysRented);
        }
        else if(choice==3)
        {
          charge = computecharges(charge, price, DaysRented, Category, CouponApplied, Tax);
        }
        else if(choice==4)
        {
          displayreceipt(Fullname, Address, City, VideoTitle, Category,
                         DaysRented, CouponApplied, Late,price, Y, Tax,charge);
        }
        else
        {
          break;
        }
    
      }
      while(choice!=5);
    
      return EXIT_SUCCESS;
      void getcustomer(char Fullname[], char Address[], char City[],
                     char CouponApplied[], char Y)
    { 
      system("cls");
    
      printf("Store Name:               %s\n\n", TITLE);
      printf("Customer Name:            ");
      gets(Fullname);
      printf("         Address:         ");
      gets(Address);
      printf("         City/State/Zip:  ");
      gets(City);
      printf("\n\n");
      printf("Coupon Presented (Y/N):   ");
      scanf("%c", &Y);
      getchar();
    
      Y = toupper(Y);
      
      if(Y = 'Y')
        strcpy(CouponApplied, "YES");
      else
        strcpy(CouponApplied, "NO");
    
    }
     void getVideos(char Fullname[],char CouponApplied[],char VideoTitle[][MAX_NAME + 1],
                   char Category[], int DaysRented[])
    { 
      int i, count;
    
      system("cls");
    
      printf("Store Name:       %s\n\n", TITLE);
      printf("Customer Name:    %s\n", Fullname);
      printf("Coupon Presented: %s\n\n", CouponApplied);
    
    
      /*user has to rent 10 videos using for loop
       to allow for any number of
       videos between 1 and 10 inclusive*/
      printf("How many videos > ");
      scanf("%d",&count);
      getchar();
      printf("\n\n");
    
      for (i = 0; i < count; i++)
      {
    
        printf("%i. VideoTitle:         ", i+1);
        gets(VideoTitle[i]);
        printf("   Category(N,R,C,B):  ");
        scanf(   "%c",&Category[i]);
    	getchar();
    	Category[i] = toupper(Category[i]);
        printf("   DaysRented:         ");
    	scanf("%d", &DaysRented[i]);
        getchar();
    	printf("\n\n");
      }
    
    }
    double computecharges(double charge, float price[], int DaysRented[], char Category[],char CouponApplied[], double Tax)
    {
      int i;
    
      i = 0;
    
      while((Category[i] != ' ') && (Category[i] != '\0'))
      {
      if (Category[i] == 'N')
      
        price[i] = DaysRented[i] * 2.99f;
      
      else if (Category[i] =='R')
      {
        price[i] = DaysRented[i] * 3.99f;
        if (strcmp(CouponApplied, "Yes") == 0)
          price[i] = price[i] - 1.0f;
      }
    
      else if (Category[i] == 'C')
      {
        price[i] = DaysRented[i] * 2.99f;
        if (strcmp(CouponApplied, "Yes") == 0)
          price[i] = price[i] - 1.0f;
      }
    
      else if (Category[i] == 'B')
        price[i] = DaysRented[i] * 1.0f;
    
      else if (DaysRented[i] == 0)  
        price[i] = 75.0f;            
                                    
      else if (DaysRented[i] == 90) 
        price[i] = 75.0f;
    
      else if (DaysRented[i] == 90) 
        price[i] = 75.0f;
      
      charge += price[i];
      i++;
      }
      
    	return charge;
    
    } 
    void displayreceipt(char Fullname[],char Address[],char City[],
                        char VideoTitle[][MAX_NAME + 1],char Category[],int DaysRented[],
                        char CouponApplied[], char Late[][5], float price[], char Y, double Tax, double charge)
    {
      int i = 0;
      system("cls");
    
      printf( "Store Name     :         %s\n\n", TITLE);
      printf( "Customer Name  :         %s\n", Fullname);
      printf(   "        Address:         %s\n", Address);
      printf( " City/State/Zip:         %s\n\n", City);
      printf("Coupon Presented (Y/N):  %s\n\n", CouponApplied);
    
    
      printf("                                         Days   Coupon  \n"); 
      printf("No. Video Title                Category  Rented Applied  Late/Lost  Charge\n"); 
      printf("=== =========================  ========  ====== ======== =========  =======\n"); 
    
      while((Category[i] != ' ') && (Category[i] != '\0'))
      {
        printf("%-1i.  %-28s%-11c%-6d%-12s%-7s%7f\n", i + 1, VideoTitle[i], Category[i], DaysRented[i],
                                           CouponApplied, Late[i], price[i]);
        i++;
      }
        Tax = 0.086 * charge;
    
      printf("\n\n                                                       Subtotal     : %5.2lf"
              "\n                                                        Tax (8.6%%)  : %5.2lf"
               "\n                                                       Total Due    : %5.2lf", charge,Tax,Tax+charge);
    
      printf("\n\nHit any key to continue");
      getchar();
    
    }
    void initialise(char VideoTitle[][MAX_NAME + 1],char Category[],char Late[][5],
                    float price[],int DaysRented[])
    {
      
      int i;
    
      for(i = 0; i < MAX_VIDEO; i++)
      {
        strcpy(VideoTitle[i], "\0");
        strcpy(Late[i], " ");
        Category[i] = ' ';
        price[i] = 0.0;
        DaysRented[i] = 0;
      }
      Category[i] = '\0';
    }
    Code tags added by kermi3

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    HEy Guys, I need help again. This is my last assignmnet and the instructor told us to change all of this to C++.
    So, are you learning C or C++ in class? Surely if you've been learning C++ then you have some idea how to start converting?
    If you haven't been learning C++, then how can you be expected to do this?

    There's a couple of bugs in your existing code anyway, so I'd suggest fixing them first.
    >if (Y = 'Y')
    .... possible incorrect use of assignment. Did you mean
    >if (Y == 'Y')

    And there's a } missing, from what I could gather, it should go after this line
    >return(EXIT_SUCCESS);

    There are many things you can do to convert a program to C++, maybe starting with replacing all the standard functions, eg printf(), scanf(), getchar(), gets() etc. Then you can move on to designing classes if you want.

    Hope this helps.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    7

    reply to hammer

    Actually I am taking C only and our instructor gave this last assignment by converting the last lab 3 to C++ or .cpp.

    I even bought this small pamplet on how C++ study guide but I cannot understand it yet. I am going to get C++ next semester.

    And thanks for your responsed to my SOS Hammer. I will try what you said.

    Mom from Seattle WA

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    7

    reply to hammer

    Actually I am taking C only and our instructor gave this last assignment by converting the last lab 3 to C++ or .cpp.

    I even bought this small pamplet on how C++ study guide but I cannot understand it yet. I am going to get C++ next semester.

    And thanks for your responsed to my SOS Hammer. I will try what you said.

    Mom from Seattle WA
    __________________
    Lokarette

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Humor him, and rename your .c files to .cpp. Assuming you aren't using malloc(), you more than likely can run your C code through a C++ compiler and have it compile and run without incident (assuming the code is correct in the first place).

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    aurė entuluva! mithrandir's Avatar
    Join Date
    Aug 2001
    Posts
    1,209
    I would question why you would need to convert that to program to C++ in the first place. It won't improve the program efficiency. Even if you wanted modify it to incoprorate object oriented design, you would need to start from scratch.

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by quzah
    Humor him, and rename your .c files to .cpp. Assuming you aren't using malloc(), you more than likely can run your C code through a C++ compiler and have it compile and run without incident (assuming the code is correct in the first place).

    Quzah.

    "Mom from Seattle WA"


    And if the instructor isnt happy with Quzah's suggestion, as if he has washed behind his ears and threaten to send him to his room
    Last edited by Fordy; 08-11-2002 at 11:36 AM.

  8. #8
    Unregistered
    Guest

    Thumbs up

    okay i will give u a template for conveting the above programme to c++.

    class Whatever{
    private:
    /* declare all of ur variables here */
    public:
    /* rewrite all of ur functions here */
    }; /* end the class */

    write the main function :

    int main(void){
    /* declare the instance of the class */
    Whatever myObject;
    myObject.mainRoutine(); // call main routine of ur problem
    }

    well u have to change the headers and std function calls but u can use std functions also. Using streams is much in sprite with C++ so its worth while to change all Std calls to stream calls::::
    printf -----> cout
    scanf -----> cin
    well look for the syntax in ur manual. they are much more simple than the printf/scanf of c.
    good luck.

  9. #9
    Unregistered
    Guest
    Wow, you're sure milking that 50 year old mom thing!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21