Question

In: Computer Science

Write using C++ a) Inputs two 1D arrays of doubles A[i] and B[i] from the keyboard...

Write using C++

a) Inputs two 1D arrays of doubles A[i] and B[i] from the keyboard with a maximum size of 1000. The elements are input one at time alternating between A and B (ie A[0],B[0],A[1],B[1], …, A[i],B[i]) until a value of less than -1.0e6 is input or i >= 1000. Then the program continues to part b).

b) Calculates C = A + B, where + is vector addition (ie C[i] = A[i] + B[i]), and prints each element of C to the screen.

c) Calculates the minimum value of A[i] and prints it to the screen.

d) Adds the elements of B[i] and prints the result to the screen.

e) Multiplies the elements of A[i] and prints the result to the screen.

f) Using an infinite loop, determines and prints out the positive integer value of k for which the expression abs(x^k / k!) is less than 1.0e-9 where x = A[0].

Solutions

Expert Solution

#include <bits/stdc++.h>

using namespace std;

double factorial(int n)

{  

    return (n==1 || n==0) ? 1: n * factorial(n - 1);  

}

int main() {

    double A[1005],B[1005],C[1005],minv=INT_MAX,sumb=0,multia=1;

    int size=0;

    for(int i=0;i<1000;i++)

    {

        cout<<"Enter the input for A array=";

        cin>>A[i];

if(A[i]<-1000000)

        break;

        if(A[i]<minv)

        minv=A[i];

       multia=multia*A[i];

       

        cout<<endl<<"Enter the input for B array=";

        cin>>B[i];

        if(B[i]<-1000000)

        break;

        sumb=sumb+B[i];

        cout<<endl;

        

        size++;

    }

cout<<endl<<"Values of vector of C=";

   for(int i=0;i<size;i++)

   {

       C[i]=A[i]+B[i];

       cout<<C[i]<<" ";

   }

   cout<<endl<<"Minimum value of A array ="<<minv<<endl;

   cout<<"Sum of B array ="<<sumb<<endl;

   cout<<"Multiplication of array of A ="<<multia<<endl;

   double x,k;

   x=A[0];

   k=1;

   while((pow(x,k)/factorial(k))>0.000000001)

   {

       k++;

   }

cout<<" k="<<k;

}


Related Solutions

In C++, write a function that takes in as inputs two arrays, foo and bar, and...
In C++, write a function that takes in as inputs two arrays, foo and bar, and their respective array sizes. The function should then output the concatenation of the two arrays as a singly linked list. You may assume that you are provided a singly linked list header file.
Using c++, write a program that reads a sequence of characters from the keyboard (one at...
Using c++, write a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered and displays the string on the screen. The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Do not use C-Strings. 2. Use the following function to append character “ch” to the string “s”: s.push_back(ch); 3. Read the input characters one by one, i.e. do...
write a python program that inputs 10 integer values from the keyboard and then displays their...
write a python program that inputs 10 integer values from the keyboard and then displays their sum. use for loop
Using C++ Write a program that reads a text from the keyboard until the user presses...
Using C++ Write a program that reads a text from the keyboard until the user presses the “Enter” key. Your program must count the number of uppercase alphabets (A through Z), lowercase alphabets (a through z), digits (0 through 9) and any other characters. The other character count value should NOT include the “Enter” key. Display the count on the screen. You must use the in-built C++ character I/O functions in this program.
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers....
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers. It should display the contents of the first array, then call a function to sort it using an ascending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using an ascending order selection sort, modified to print out the...
C++ Assignment Inheritance This uses some single arrays of doubles. We can use Vectors instead if...
C++ Assignment Inheritance This uses some single arrays of doubles. We can use Vectors instead if we want! Choice either vectors or arrays either one is fine We will implement a classic Inheritance hierarchy. A simple console based interface is all that is needed. Build your classes first, each in their own .h and .cpp files, then test them with the simple main method provided below. Phase 1 : Here is the following set of classes you will implement and...
Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files...
Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files 1. WriteaclassGradeBookcontainingthefollowing: Private attributes: - courseName: a string representing the name of the course. - nbOfStudents: an integer representing the number of students enrolled in the course. The number of students is greater than or equal to 5. - grades: a double dimensional array of integers representing the grades of Test1, Test2 and Final of every student. It should be a dynamic array. Public...
Write a C++ program to read in a list of 10 integers from the keyboard. Place...
Write a C++ program to read in a list of 10 integers from the keyboard. Place the even numbers into an array called even, the odd numbers into an array called odd, and the negative numbers into an array called negative. Keep track of the number of values read into each array. Print all three arrays after all the numbers have been read. Print only the valid elements (elements that have been assigned a value). a. Use main( ) as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT