Surya
Surya

Reputation: 153

When I have two .cpp files from the same set of source files in Code::Blocks, how can I run one of them?

I have two different .cpp files (linked lists) under the same set of source of one project. I tried running one of the linked list files called "customer", but it's only running the other one called "video". How can I run the "customer" linked list file?

My customer.cpp file is active but it's still running the program for the "video" linked list file.

Basically Im trying to bring two seperate lists of customers and another seperate list with videos.

But when I try executing the program under the customer.cpp tab I thought it was supposed to run that but its running the video.cpp file...am I missing something here?

#include <iostream>
using namespace std;

struct video
{
 char title[40],star1[20],star2[20],star3[20],star4[20],prod[20],dir[20],proco[40];
 int copy;
 video *next;
 };
 video *first = NULL, *current = NULL;
  int optn = 0;

^this is my nodestructure for the video list the video.cpp file

   #include <iostream>
   using namespace std;

   struct customer
   {
   char f_name[20],l_name[20];
    int acc_num;
    customer *next;
     };
     customer *start = NULL, *pointer = NULL;
     int option = 0;

^this is my nodestructure for customer linked list.the customer.cpp file .both of these are in two seperate source files under the same project.

int main(void)
{
 first = NULL;
 current = NULL;
 do
    {
        display();
        cout << endl;
        cout << "Choose an option: " << endl;
        cout << "1. Move the current position forward once." << endl;
        cout << "2. Move the current position backwards once." << endl;
        cout << "3. Add a video at the beginning of the list." << endl;
        cout << "4. Add a video at the current position of the list." << endl;
        cout << "5. Add a video at the ending of the list." << endl;
        cout << "6. Delete the first video from the list." << endl;
        cout << "7. Delete the video at current position from the list." << endl;
        cout << "8. Delete the last video from the list." << endl;
        cout << "9. End program." << endl;
        cout << endl << " >> " ;
        cin >> optn;
         switch (optn)
        {
            case 1 : currentfor();
            break;
            case 2 : currentbac();
            break;
            case 3 : addbeginning();
            break;
            case 4 : addmiddle();
            break;
            case 5 : addending();
            break;
            case 6 : deletebegin();
            break;
            case 7 : deletemiddle();
            break;
            case 8 : deleteend();
            break;
        }
    }
    while (optn != 9);
   }

^this is the code where i call all the functions for the video.cpp file.

     int mains(void)
     {
     start = NULL;
     pointer = NULL;
    do
      {
        display_menu();
        cout << endl;
        cout << "Choose an option: " << endl;
        cout << "1. Move the current position forward once." << endl;
        cout << "2. Move the current position backwards once." << endl;
        cout << "3. Add a customer at the beginning of the list." << endl;
        cout << "4. Add a customer at the current position of the list." << endl;
        cout << "5. Add a customer at the ending of the list." << endl;
        cout << "6. Delete the first customer from the list." << endl;
        cout << "7. Delete the customer profile at current position from            the         list." << endl;
        cout << "8. Delete the last video from the list." << endl;
        cout << "9. End program." << endl;
        cout << endl << " >> " ;
        cin >> option;
         switch (option)
        {
            case 1 : current_forward();
            break;
            case 2 : current_backward();
            break;
            case 3 : add_beginning();
            break;
            case 4 : add_middle();
            break;
            case 5 : add_ending();
            break;
            case 6 : delete_beginning();
            break;
            case 7 : delete_middle();
            break;
            case 8 : delete_ending();
            break;
        }
    }
    while (option != 9);

   }

^this is the final code where i call all functions for customer.cpp file... when I tried initially with int main(void) for the customer.cpp,the compiler showed an error saying that "main" was declared in both video.cpp and customer.cpp so I tried changing "main" to "mains" then it dint show any error...what did I miss here?

Upvotes: 1

Views: 1256

Answers (1)

fpointbin
fpointbin

Reputation: 1663

If you wanna run only the customer implementation, you should have:

"Customer.h"-header file "Customer.cpp"- implementation or definitition of the class or whatever... "main.cpp" - the main file, in wich:

#include <iostream>
#include <Customer.h>
int main()
{
  ...
  ...
}

If you have got 2 diferent classes derivated from a linked list class, i think you should split the customer class and the video class, with each implementation files...

If it is not the correct answer, please put some code to guide us with your class definitions :)

Upvotes: 1

Related Questions