Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what exactly are driver functions?

Tags:

c++

I'm working through "Accelerated C++". I have a question about problem 5-3. It asks:

5-3. By using a typedef, we can write one version of the program that implements either a
vector-based solution or a list-based one. Write and test this version of the program.'

The next question asks:

5-4. Look again at the driver functions you wrote in the previous exercise. Note that 
it is possible to write a driver that differs only in the declaration of the type for the data structure
that holds the input file. If your vector and list test drivers differ in any other way, rewrite them
so that they differ only in this declaration.

What exactly are driver functions? I've solved 5-3 by creating if statements as well as overloaded functions to deal with different datatypes like so:

cout << "Please enter 1 if you would like to use vectors, or 2 if you would like to use lists: "<< endl;
int choose;
cin >> choose;
//CHOOSING TO USE VECTORS
if (choose == 1){....vector<Student_info> allStudents;
                 vector<Student_info> fail;.......} 

//CHOOSING TO USE LISTS
else if (choose==2) {....list<Student_info> allStudents;
                    list<Student_info> fail;....}

//INVALID CHOICE
else {...invalid number, try again...}

I did not create any extra functions besides the overloaded ones to deal with different data types. Are those driver functions? If not, I must be doing the problem wrong. Could someone shed some light? :>

like image 244
zzz2991 Avatar asked Jan 12 '14 00:01

zzz2991


People also ask

What are driver functions?

A driver provides a software interface to hardware devices, enabling operating systems and other computer programs to access hardware functions without needing to know precise details about the hardware being used.

Why main function is called driver function?

Driver functions are probably functions that are written to demonstrate operation of some library-style code that solves the problem. For example, if you write some class A , driver functions would be functions that are in your code just to show that class A behaves as expected.

What is a driver function in Python?

A driver script is a short program, written in the Python programming language, which is used to directly configure a device via the Oracle Communications IP Service Activator device drivers. Python allows the use of loops and if/then statements when generating device commands.

Which function is called the driver program in C?

1 Answer. +3. Because main() function is like opening and closing of any c or c++ programming language also it drive all the elements and we know already if we not write main() function the code is wrong :/ BTW The main() function is implicitly called by the C library by recognizing the in-built keyword 'main'.


1 Answers

Inside your two if blocks, how similar is the code that operates on allStudents and fail regardless of whether they are list or vector? If you've done the assignment correctly, there is probably little or no difference. Now if you take that code out and remove references to list and vector and instead operate on mytype where you build either with typedef vector<Student_info> mytype or typedef list<Student_info> mytype you will have what they were calling a "driver function". It's not a formal name you're going to find internet references to. They were just describing the code that drives the list and vector operations to get the answer.

like image 137
Ben Jackson Avatar answered Oct 04 '22 12:10

Ben Jackson