Question

In: Computer Science

1.Using C++ code, write a program named q4.cpp to compute the product (multiplication) of 4 integers...

1.Using C++ code, write a program named q4.cpp to compute the product (multiplication) of 4 integers a, b, c and d, where a is input by a user via the keyboard, b = 2a - 1, c = ab - 2 and d = |a - b - c|.

2.Using C++ code, write a program named q5.cpp to solve the equation 2n = 14.27 for n.

3.Using C++ code, write a program named q3.cpp to divide each of the elements of a 3- element array T of real values by the sum of the elements of T, each of which is input by a user via the keyboard.

Solutions

Expert Solution

Problem 1: The following is q4.cpp

#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d,product;
    cout<<"Enter the value of a: ";
    cin>>a;  //take the input a
    cout<<endl; //print new line
    b=2*a-1; //calculate b
    c=a*b-2; //calculate c
    d=abs(a-b-c); //calculate d; here abs will give us the modulus of an integer i.e returns positive value
    product=a*b*c*d;  //calculate product
    cout<<"The product a*b*c*d is : "<<product<<endl; //print the product

    return 0;
}

Output:

Enter the value of a: 3

The product a*b*c*d is : 2925

Problem 2: The following is q5.cpp

#include <iostream>
using namespace std;
int main()
{
    double n; //declare it as either double or float
    n=14.27/2; //since 2n=14.27, n will be 14.27/2;
    cout<<"The value of n for the equation 2n=14.27 is "<<n; //print the value of n

    return 0;
}

Output:

The value of n for the equation 2n=14.27 is 7.135

Problem 3: The following is q6.cpp

#include <iostream>
using namespace std;
int main()
{
   int T[3],i,sum=0; //declare an array T with size 3 and sum of type int to 0
   double value;
   cout<<"Enter the 3 values of an array: "<<endl;
   for(i=0;i<3;i++)
   {
       cin>>T[i]; //input the values entered by user and store in T array
       sum=sum+T[i];  //add the values to calculate sum
   }
    for(i=0;i<3;i++)
   {
       value=((double)T[i]/(double)sum); //Here type conversion is very important. Since sum and array values are int, we have to convert them to double and apply division. The result will be stored in value.
      cout<<"The value when "<<T[i]<<" is divided by sum is "<<value<<endl; //print the required result
      
   }
   

    return 0;
}

Output:

Enter the 3 values of an array:
3
4
5
The value when 3 is divided by sum is 0.25
The value when 4 is divided by sum is 0.333333
The value when 5 is divided by sum is 0.416667


#Please dont forget to upvote if you find the solution helpful. Feel free to ask doubts if any, in the comments section. Thank you.


Related Solutions

Using C++ code, write a program named q3.cpp to compute the total amount of medicine m...
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m absorbed by a rabbit, where the rabbit gets 2 pills containing n1 and n2 grams of medicine, respectively, of which the rabbit absorbs 60% and 35%, respectively, and n1 and n2 are input by a user via the keyboard.  
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m...
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m absorbed by a rabbit, where the rabbit gets 2 pills containing n1 and n2 grams of medicine, respectively, of which the rabbit absorbs 60% and 35%, respectively, and n1 and n2 are input by a user via the keyboard.
Using C++ code, write a program named q5.cpp to print the minimum of the sums x...
Using C++ code, write a program named q5.cpp to print the minimum of the sums x + y^3 and x^3 + y, where x and y are input by a user via the keyboard.
Using pseudocode or C++ code, write a function to compute and return the product of two...
Using pseudocode or C++ code, write a function to compute and return the product of two sums. The first is the sum of the elements of the first half of an array A. The second is the sum of the elements of the second half of A. The function receives A and N ≥ 2, the size of A, as parameters. (in c++)
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
use cpp 1 a)Write a console program which creates an array of size 100 integers. Then...
use cpp 1 a)Write a console program which creates an array of size 100 integers. Then use Fibonacci function Fib(n) to fill up the array with Fib(n) for n = 3 to n = 103: So this means the array looks like: { Fib(3), Fib(4), Fib(5), ...., Fib[102) }.  For this part of assignment you should first write a recursive Fib(n) funcion, as was done in class.For testing, print out the 100 integers. 1 b) For second part of this assignment,...
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
Code is in C Write a program that reads integers from stdin. Once it reaches the...
Code is in C Write a program that reads integers from stdin. Once it reaches the * end of the input, it prints the smallest absolute value among those * of the numbers it read. * * For example, if * 4, 6 -3, 3, -2, 13, -4 * are read from stdin, the program should print 2. * * If the end of file is reached before any integer is seen, the * number printed should be INT_MAX (defined...
Write a C++ program based on the cpp file below ++++++++++++++++++++++++++++++++++++ #include using namespace std; //...
Write a C++ program based on the cpp file below ++++++++++++++++++++++++++++++++++++ #include using namespace std; // PLEASE PUT YOUR FUNCTIONS BELOW THIS LINE // END OF FUNCTIONS void printArray(int array[], int count) {    cout << endl << "--------------------" << endl;    for(int i=1; i<=count; i++)    {        if(i % 3 == 0)        cout << " " << array[i-1] << endl;        else        cout << " " << array[i-1];    }    cout...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT