c++ - Using Other Programs as Part of Another Program -


i'm working last programming assignment of semester (my last computer program ever guess seeing changed majors ha) , have kind of run roadblock. assignment asks write 2 programs, 1 program reads in information file , creates hash table saves output file. second program supposed allow user enter key , program search output file key , return information contains if found.

i'm still in planning stages of program, write them out on paper before start coding since reason kind of helps me figure out what's going on better, think program creates hash table should work since it's identical program had write couple weeks ago created hash table (fingers crossed), i'm having problem on search program. search program has 1 method search file key entered user. may easier explain specific issue if include code search function used in program mentioned created hash table.

void hash::finditem(int key) {     int index = hash(key);     bool wasfound = false;     record* ptr = hashtable[index];     while(ptr != null) {         if(ptr->key == key) {             wasfound = true;             key = ptr->key;         }         ptr = ptr->next;     }     if(wasfound == true) {         cout << key << " " << name << " " << code << " " << cost << " " << index << endl;     }     else {         cout << "the key " << key << " not found in table." << endl;     } } 

hash name of class used in program creates table, , record name of struct used hold information each record. else should pretty self-explanatory.

so here's i'm running trouble. pretty in code declared , defined in first program, method/function (not sure on correct terminology, i'm taking 3 programming classes in 3 different languages live in constant state of confusion) used in search program. i'm not sure how go connecting 2 programs (if makes sense). like, how can make things created in first program usable search program?

i apologize rambling, i'm no better @ short , sweet @ programming. , that's pretty clear. if need include additional information please let me know , i'll happy oblige. in advance fine folks able provide.

note used "inheritance" 1 of tags post, i'm not sure issue inheritance, felt might be. if feel otherwise please let me know , can remove want sure doesn't wind in wrong place , wast anyone's time.

let have 4 files:

  • common.h - type declarations common staff
  • common.cpp - common staff function bodies
  • main1.cpp - 1st executable
  • main2.cpp - 2nd executable

all cpp files should include common.h

now can compile follows: can add -g each line if want debug.

g++ -c common.cpp -o common.o  g++ -c main1.cpp -o main1.o g++ -c main2.cpp -o main2.o g++ main1.o common.o -o main1 g++ main2.o common.o -o main2 

the first 3 lines compile source file object file.

the last 2 link objects executable.

note need have 4 files...


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -