Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN C LANGUAGE Create a struct TempData which has an integer representing time an

ID: 3764151 • Letter: I

Question

IN C LANGUAGE

Create a struct TempData which has an integer representing time and a double field representing temperature. 3. Create a function that takes an array of TempData, the size of the array and an integer variable num as arguments. The function should return the array index for the time num (index number of the array element that contains the value num in the time field). 4. Your program should read in the data from the input file into an array of TempData of size 50. 5. Your program prints out the time field for the first and last data points. 6. Then, your program asks the user for two numbers: the lower limit of the desired time interval and upper limit of the time interval, separated by a comma. 7. For m=0.5 and Cp=380, calculate the amount of heat transferred to the sphere during the given time interval. 8. Your program should print out the values for t, Q, and the data during the interval to the console screen and to an output file (i.e., write out the same information to the console and the output file Output.txt).

Explanation / Answer

2)

A struct is a type used to represent a heterogeneous collection of data; it is a mechanism for treating a set of different types as a single, coherent unit. For example, a student may have a name, age, gpa, and graduation year. A struct type can be defined to store these four different types of data associated with a student.

In general, there are three steps to using structured types in C programs:

Defining a struct type

struct type definitions should appear near the top of a program file, outside of any function definition. There are several different ways to define a struct type but we will use the following:

Here is an example of defining a new type 'struct studentT' for storing student data:

Declaring variables of struct types

Once the type has been defined, you can declare variables of the structured type:

Accessing field values

To access field values in a struct, use dot notation:

It is important to think very carefully about type when you use structs to ensure you are accessing field values correctly based on their type. Here are some examples:

structs are lvalues, meaning that you can use them on the left-hand-side of an assignment statement, and thus, can assign field values like this:

3)

template <class T, class B>

class SelectionSort

{

    public:

        void IterativeSort(T &data, B size)

        {

            for (unsigned int index = 0; index < size; index++)

            {

                int smallestNum = index;

                for (unsigned int inner = index; inner < size; inner++)

                {

                    if (data[smallestNum]>data[inner])

                    {

                        smallestNum = inner;

                    }

                }

                int temp = data[smallestNum];

                data[smallestNum] = data[index];

                data[index] = temp;

            }

        }

}

array call:

// sort copy of small array with iteration

SelectionSort<int, int> smallArrayIterativeSort;

smallArrayIterativeSort.IterativeSort(copySmallArray, smallSize);

vector call:

// sort small vector with iteration

SelectionSort<vector <int>, int> smallVectorIterativeSort;

smallVectorIterativeSort.IterativeSort(smallVector, smallSize);