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.
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++
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...
In C++, Write the definition of the function MaximumCount() whose header is int MaximumCount(Array<double>& data) It...
In C++, Write the definition of the function MaximumCount() whose header is int MaximumCount(Array<double>& data) It returns the amount of times the maximum value of data appears in data. If data is empty, it returns 0. For instance, if data = [7, 1, 4, 9, 6, 7, 7, 3, 2, 6, 9, 5, 9], it will return 3 since 9 appears three times
Question 31 Given the code snippet below, what prints? void fun(int *p) { int q =...
Question 31 Given the code snippet below, what prints? void fun(int *p) { int q = 10; p = &q; } int main() { int r = 20; int *p = &r; fun(p); cout << *p; return 0; } Question 31 options: 10 20 compiler error Runtime error Question 32 A union’s members are exactly like the members of a Structure. Question 32 options: True False Question 33 Given the code below, what are the errors. #include <iostream> using namespace...
/*Use recursion in the function: void getDigit( int num) /* Try this program and implement the...
/*Use recursion in the function: void getDigit( int num) /* Try this program and implement the function void getDigit( intnum) so that it displays the digits in a given number. For example, the number, 1234 consist of 1, 2, 3 and 4. This is an exercise to demonstate the use of a recursive function and the use of recusrion in C++ */ #include #include using namespace std; int main() {      int num;      cout <<"Enter an integer: ";     ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT