Question

4.2. The binomial theorem can be written as 4.3. W A d SS a-2h2 n(n - 1)(n - 2) 2! (a+ b) = a+1na-1hn(n-1) 3! Write a pro

Input data from a file called BINO,DAT. The first line of the file con- sists of the number of values, m, of b and n that wil

The problem is in these two pictures, please show me the source code~

1 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <math.h>
#include<fstream>
 
// function to calculate the factorial
int factorial(int n)
{
int fact = 1;
for (int i = 2; i <= n; i++)
fact *= i;   
return fact;
}
 
 
   
// fuction to calculate sum of the series
void series(int a, float b, int n)
float sum = 0;
for(int i = 0; i< n+1; i++){
int numfact = factorial(n); // calculates numerator n!
int denfact = factorial(n - i); //calculates denominator of ncr (n-i)!
int intfact = factorial(i); //calculates denominator of ncr i!
float ncr = numfact/(denfact * intfact); //final value of ncr
   
float A = pow(a,(n-1)); // calculates a term of binomial theorem
float B = pow(b,i); // calculates b term of binomial theorem
 
float mult = ncr*A*B; //represnts every single term of the binomial series
   
sum+= mult; //final sum
}
std::cout<<"(a+b)^n from binomial theorem: "<< sum <<"\n";
}
 
//function gets number from the file
void getNumber(float& num, std::istream& inf)
{
inf >> num;
}
 
 
//main function
int main() {
int m; //value of m from the file
int a = 1;
float b;
float n;
 
std::ifstream inf;
inf.open("BINO.DAT");
inf >> m; //value of m is recorded
for(int i = 0; i<2*m; i++){
getNumber(b ,inf); //value of b is recorded here
i++;
getNumber(n, inf); //value of n is recorded here
series(a,b,n); //represents binomial answer
std::cout<<"(a+b)^n from pow() function: "<<pow(a+b,n)<<"\n\n"//represents pow() function answer
}
}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
The problem is in these two pictures, please show me the source code~ 4.2. The binomial theorem can be written as 4.3....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please show me the source code of this problem with C language (I only learned C...

    Please show me the source code of this problem with C language (I only learned C before), thank you~ the Note that you must display 4.4 Write a program that computes the sum of all the negative integers in a list As input, the program is to read the data from the data file SUMNEG. 8.80.0 of integers. dugio DAT. The data file has the following format: ore (number of integers in list) line 1 dugdeer ) wo bne line...

  • C++ Can someone please help me with this problem- commenting each line of code so I...

    C++ Can someone please help me with this problem- commenting each line of code so I can understand how to solve this problem using the C++ programming language? I really need help understanding how to create a file for the program to read. Do I create the file in Visual basic or create a text file? I have the code, just need to know how to create the file for it to read. #include<fstream> #include<iostream> using namespace std; int main()...

  • please write a C++ code Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj...

    please write a C++ code Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj Input file: shadow.in in reality, when we read an English word we normally do not read every single letter of that word but rather the word's "shadow" recalls its pronunciation and meaning from our brain. The word's shadow consists of the same number of letters that compose the actual word with first and last letters (of the word) in their original positions while the...

  • Can some help me with my code I'm not sure why its not working. Thanks In...

    Can some help me with my code I'm not sure why its not working. Thanks In this exercise, you are to modify the Classify Numbers programming example in this chapter. As written, the program inputs the data from the standard input device (keyboard) and outputs the results on the standard output device (screen). The program can process only 20 numbers. Rewrite the program to incorporate the following requirements: a. Data to the program is input from a file of an...

  • I am really struggling with quantum. Can someone please help me with those questions 4.2. Using...

    I am really struggling with quantum. Can someone please help me with those questions 4.2. Using basic quantum concepts Pr 4.3 This problem reinforces your understanding of normalization, prob- ability densities, and mean (expectation) values. The ground state wave function for a particle in a wire is = (2/a)/2 sin(x/a). (a) Define the ground state wave function for the particle in a wire using Maple. Hint: see Appendix A. (b) Write down a mathematical expression for the normalization of the...

  • Please help me with the coding for LL(1)!! The given grammar was: P → PL |...

    Please help me with the coding for LL(1)!! The given grammar was: P → PL | L L → N; | M; | C N → print E M → print "W" W → TW | ε C → if E {P} | if E {P} else {P} E → (EOE) | V (note: this has a variable O) O → + | - | * V → 0 | 1 | 2 | 3 (note: this has a terminal...

  • Hello, I need help with these two functions blockPrint and wordPrint.The program is written in C....

    Hello, I need help with these two functions blockPrint and wordPrint.The program is written in C. Thank you. ent the prototype for blockPrint. a) Intextfunctions.h, uncon Write the function definition for block Print dentical characters on a separate line. (See example This function should print each group (block) of ident output below) Example: Example: Incoming string: "Tbeehiklssuy Output (to the screen): Incoming string: "Java Programming Output to the screen: ee POOH da al Edit vour main function.include test calls and...

  • Python Problem, just need some guidance with the description, pseudocode and run time. I believe this...

    Python Problem, just need some guidance with the description, pseudocode and run time. I believe this is an 0-1 knapsack problem? Shopping Spree: (20 points) Acme Super Store is having a contest to give away shopping sprees to lucky families. If a family wins a shopping spree each person in the family can take any items in the store that he or she can carry out, however each person can only take one of each type of item. For example,...

  • C++ Code

    "For two thousand years, codemakers have fought to preserve secrets while codebreakers have tried their best to reveal them." - taken from Code Book, The Evolution of Secrecy from Mary, Queen of Scots to Quantum Cryptography by Simon Singh.The idea for this machine problem came from this book.You will encrypt and decrypt some messages using a simplified version of a code in the book. The convention in cryptography is to write the plain text in lower case letters and the encrypted text in upper case...

  • This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process...

    This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process and then use the parent for reading and the child for writing.  This is just a way of sending and receiving messages asynchronously. /* ************************************************************* * Utility functions * ************************************************************** */ static void usageError(const char * progName, const char *msg) {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT