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.
Write a program in C++ that declares an array of 100 integers named scores[]. Prompt the...
Write a program in C++ that declares an array of 100 integers named scores[]. Prompt the user for how many scores they want to enter. Then read in the specified number of ints and store them in the array. Then prompt the user for a passing grade. Use a for loop to go trough the array and count how many scores are passing. Print the count of how many passing scores, and also print a double that is the percent...
Create a c++ program to compute the product of two integers. call create the following functions:...
Create a c++ program to compute the product of two integers. call create the following functions: 1. getNum - to accept only positive numbers && will call computeProd. 2.computeProd - to compute the product of the numbers & will call the function displayProduct. 3. displayProduct - to display the product. Call the function getNum in the main function. Compute the product w/o using the multiplication operator(*). using #include <iostream> only
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,...
For this C++ program, Write and modify the code to compute and display the class average...
For this C++ program, Write and modify the code to compute and display the class average as well as the standard deviation. Your code changes are as follows: 1. The variable “double grade” should be replaced by a two-dimensional array variable “double grade[NUMSTUDENTS][NUMGRADES].” Also replace the variable “double average” by “double average[NUMSTUDENTS].” This is necessary since you need to save the entered grades specially to compute the standard deviations. 2. After completing the display of the average grade of all...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT