1>
To the 'test' function we are passing one argument(x) as call by value and next argument(y) as call by reference. Which mean whatever changes done to y in 'test' will reflect in main function also; but for x it will not. Now in main function we pass 'test(45,43)'. Now a=45 and b =43. if(a>b) becomes true and b=a%2 is executed.45%2 is 1. Now a=45 and b=1 so finally when we print values of x and y, it will print 45 1.

2>
Write a function that takes an integer as its sole parameter and returns -1, 0 or 1 depending upon whether the integer is odd, zero or even respectively.
if(n%2==1)//if remider is 1 after
dividing by 2 then number is odd. We use modulo operator
return -1;
else if(n==0)//We use simple equality operator for checking if the
number is 0
return 0;
else//if the number is not odd or 0 then number is even
return 1;


3>
Write a function addFractions that takes as input four integers representing the numerators and denominators of two fractions, adds the fractions, and returns the numerator and denominator of the result. Note that this function should have a total of six parameters. Hint: a/b + c/d = (ad+bc)/bd.
#include<iostream>
using namespace std;
void test(int a,int b, int c,int d,int *x,int *y)//a,b,c,d are
fractionals and x and y are the addresses of
{
//
numerator and denominators are stored.
*x=a*d+b*c;
*y=b*d;
}
int main()
{
int *numerator,*denominator,nume,denom;
numerator=&nume;//The variable for storing numerator. the
address will be passed to function
denominator=&denom;//The variable for storing denominator. the
address will be passed to function
test(1,2,3,4,numerator,denominator);
cout<<nume<<endl<<denom;
}


4>
Write out the contents of the array a after the following code executes:
The output will be 4 4 8 8.
a[0]=4
The for loop starts
i=1
a[1]=2*1+2=4
if condition fails
i=2
a[2]=2*2+2=6
if condition true
a[2]=2*a[2] - a[1]=8
i=3
a[3]=2*3+2=8
if condtion true
a[3]=2*a[3] - a[2]=8
finally we have a[0]=4, a[1]=4, a[2]=8,a[3]=8
Here is a function that takes, and returns pointers: 2 int* select(bool which, int* a, int* b) { if(which == true) return a; else return b; } Using this function, suppose we have variables x, y: int x = ..., y = ...; int* p = select(x < y, &x, &y); if(p == &x) cout << "Yes"; else cout << "No"; What will this print if x = 5, y = 7? What will this print if x = 23, ...
Haskell code: checkIfEven :: Int -> Bool x <- readLn let checkIfEven x = (even ((x*3)+1)) print checkIfEven Getting error : Variable not in scope: checkIfEven :: Int -> Bool, how to fix it? note: function goal is take an int and return a bool. takes the integer multiplies it by 3 and adds 1. if the the outcome is even return true, otherwise false.
In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an array (allocated off of the heap in the function) containing only the elements of array a that pass the “test” t. The function iterates through all the elements of a, and constructs a new array containing all the elements that pass the test. When the parameter corresponding to “size” is passed in (by reference), it contains the size of the array a. In the...
Using C++
Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...
TestScores . SIZE: int //size of the array scores: int [ 1 estScores findMax ( ) : int findMin ) int findScore (value: int): bool res(): int Write the constructor method. It fills the array with random number from 0-100. Find below the code to get your started 1. public TestScores () Random rand -new Random); for (int i-0 i<SIZE i+) socresi] -rand.nextInt (101); Finding the maximum value in an array. Write the method findMax. It returns the maximum value...
Problem 1 1. Consider the following function (K is the size of array A and L is the size of array B) bool func (int A[], int K, int B[], int L, int start) { if (L > K-start) return false; for (int i =0; i < L; i++) { if(A[start+i] != B[i]) return false } return true; } What are the input and output variables to this function. Trace it for the following call: int F[] = {1, 3,...
C programm , ´hello i need your help -Given the C program primes.c with the following main method: int main() { int num, res; char buffer[11]; bool finished = false; while (!finished) { printf("Enter n > 0 or quit\n"); scanf("%10s", buffer); if (strcmp(buffer, "quit") == 0) { finished = true; } else { // Convert input to number and compute n-th prime num = atoi(buffer); if (num > 0) { res = nth_prime(num); printf("Prime #%d is %d\n", num, res); }...
help code failing test
96 Test void test SortedAscendingRun() { int[] A {1, 0, 1, 0, 1, 2, 1, 2, 3, 4}; 970 198 299 300 301 302 303 304 305 306 307 assertEquals(ArrayPractice. sortedAscendingRun(A, 0), 1); assertEquals(ArrayPractice. sortedAscendingRun(A, 1), 2); assertEquals(ArrayPractice. sortedAscendingRun(A, 3), 3); assertEquals(ArrayPractice. sortedAscendingRun(A, 6), 4); } -OOH /* Returns the number of items in the array that A references starting at index x tha /* ascending sorted order. */ /* For example, if the array is:...
NEED ASAP PLEASE HELP
Task:
---------------------------------------------------------------------------------------------------------------------------------
Tasks to complete:
----------------------------------------------------------------------------------------------------------------------------------------
given code:
-----------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include <iostream>
#include <iomanip>
#include "fractionType.h"
using namespace std;
int main()
{
fractionType num1(5, 6);
fractionType num2;
fractionType num3;
cout << fixed;
cout << showpoint;
cout << setprecision(2);
cout << "Num1 = " << num1 << endl;
cout << "Num2 = " << num2 << endl;
cout << "Enter the fraction in the form a / b: ";
cin >> num2;
cout << endl;
cout <<...
QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...