Question

In: Computer Science

Part 1.1 Write a function whose prototype is void exchange ( /*inout*/ int *p, /*inout*/ int...

Part 1.1

Write a function whose prototype is

void exchange ( /*inout*/ int *p, /*inout*/ int *q )

that takes two pointers to integer variables and exchanges the values in these variables.

Part 1.2

Write a function whose prototype is

char lastChar ( /*in*/ const char *str )

that takes a nonempty C-String as parameter and returns the last character in the string. For example the call lastChar ("srjc") will return the character c.

Part 1.3

Define an array of 35 of the Car structure variables.

Initialize the first three elements with the following data:

Make Model   Year Cost
Ford Taurus 1997 $ 21,000
Honda Accord 1992 $ 11,000
Lamborghini Countach 1997 $ 200,000

Solutions

Expert Solution

Part 1.1

//function to swap two integer variable using pointere
void exchange(int *p, int *q)
{
//temp variable declaration
int temp;
  
//swap the values
temp = *p;
*p = *q;
*q = temp;
}

The screenshot of the above source code is given below:

Part 1.2

//function to returns the last character in the string
char lastChar(const char *str)
{
int size=0;
while(str[i] != '\0')
size++;
  
size--;
  
return str[size];
}

The screenshot of the above source code is given below:

Part 1.3

//car structure
struct Car
{
//variable
char Make[20];
char Model[20];
int Year;
float Cost;
};

struct Car c[35];

//initialize the first car structure variable
strcpy(c[0].Make, "Ford");
strcpy(c[0].Model, "Taurus");
c[0].Year = 1997;
c[0].Cost = 21000;

//initialize the second car structure variable
strcpy(c[1].Make, "Honda");
strcpy(c[1].Model, "Accord");
c[1].Year = 1992;
c[1].Cost = 11000;

//initialize the third car structure variable
strcpy(c[2].Make, "Lamborghini");
strcpy(c[2].Model, "Countach");
c[2].Year = 1997;
c[2].Cost = 200000;


Related Solutions

IN C Write a function in the form: void play( int key, int duration) // duration...
IN C Write a function in the form: void play( int key, int duration) // duration units are tenths of a second which generates and prints samples of sin(w*t) for t=0,1,2,...,n-1 which represent a tone corresponding to piano key number key, where: n = (duration/10.0)*8000 w = (2π440rkey-49)/8000 r = 21/12 In the main program call your function to play the first three notes of three blind mice.
Write a MIPS function using a MARS 4.5 complier named void makeRandomArray(int arr[], int size) that...
Write a MIPS function using a MARS 4.5 complier named void makeRandomArray(int arr[], int size) that generates and stores a specified number of random numbers each of whose values are between 0 and 1000 in an array
Programmer defined Function / Arrays: 1.Write a function for printing an array. void print_array (int arr[],...
Programmer defined Function / Arrays: 1.Write a function for printing an array. void print_array (int arr[], int size); 2. Write a function to generate an array of random integers. void random_array (int arr[], int size, int range); The scale of numbers should be 1 to range. 3. Write a function to find the sum of a sequence of number. int sum (int arr[], int size); 4. Write a function rotate(arr[], d, n) that rotates arr[] of size n by d...
What is time Complexity each of the following function? 1- void function(int n) {             for (int...
What is time Complexity each of the following function? 1- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n/2; j++)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 2- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n; j = 2 * j)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 3- void function(int n) {             for (int i=1; i<=n; i++)                           for (int j=1;...
4, Make the table project with C++. Write a function with the following interface: void multiplyTable(int...
4, Make the table project with C++. Write a function with the following interface: void multiplyTable(int num) This function should display the multiplication table for values from 1...num. For example, if the function is passed 10 when it is called, it should display the following: 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20...
why my code for mergesort always wrong ? void Merge(vector<int>& data, int p, int q, int...
why my code for mergesort always wrong ? void Merge(vector<int>& data, int p, int q, int r) { int n1 = q - p + 1; int n2 = r - q; vector<int>left(n1); vector<int>right(n2); for(int i = 0; i < n1; i++) { left[i] = data[p + i]; } for(int j = 0; j < n2; j++) { right[j] = data[q+j+1]; } int i = 0; int j = 0; for(int k = p; k <= r; k++) { if(left[i]...
Assume that struct Node{        int item;        Node* link; }; Write function void list_remove(NodePtr& prev_ptr);...
Assume that struct Node{        int item;        Node* link; }; Write function void list_remove(NodePtr& prev_ptr); The function will remove the node after the node pointed by prev_ptr. c++
Write a method with the following header: public static void showGradeDistribution(int a, int b, int c,...
Write a method with the following header: public static void showGradeDistribution(int a, int b, int c, int d, int f) It should print a graph (using asterisks) for each of the letters entered in the reverse order of the parameter list and with a label. In addition, if A and B grades sum is equal or exceeds that of grades C and D and F, the message “Strong class!” should be displayed. For example a method call of: showGradeDistribution(5,7,4,4,3); Would...
answer in c++ , Write the definition of the function NthOccurrence() whose header is int NthOccurrence(Array&...
answer in c++ , Write the definition of the function NthOccurrence() whose header is int NthOccurrence(Array& data,const T& value,int n) template It returns the index of the nth occurrence of value in data. If n is not positive, value appears less than n times in data or data is empty, it returns -1.
Write a Haskell function combine :: Int -> Int -> Int -> Int with the following...
Write a Haskell function combine :: Int -> Int -> Int -> Int with the following behavior: • When x, y, and z all correspond to digit values (i.e., integers between 0 and 9, inclusive), combine x y z returns the integer given by the sequence of digits x y z. (That is, x is treated as the digit in the hundreds place, y is treated as the digit in the tens place, and z is treated as the digit...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT