Page 1 of 1

Program Description: Your program is to perform the following operations. 1. Output standard Header Put all of your stan

Posted: Thu Jul 14, 2022 2:17 pm
by answerhappygod
Program Description Your Program Is To Perform The Following Operations 1 Output Standard Header Put All Of Your Stan 1
Program Description Your Program Is To Perform The Following Operations 1 Output Standard Header Put All Of Your Stan 1 (145.01 KiB) Viewed 37 times
#include<iostream>#include<cmath>#include<fstream>using namespace std;
// method to write the header partvoid ShowHeader(){ FILE *wfile; wfile = fopen("table.txt", "w"); fprintf(wfile, "table.txt"); fclose(wfile);}
// method to write the table of functionsvoid writeTable(){ FILE *wfile; // open file to append wfile = fopen("table.txt", "a"); fprintf(wfile, "\n\n"); int i; // for each number in the given range, write itsresults in the file for(i=1; i<=50; i++) if(i <= 10 || i%5 == 0) fprintf(wfile, "%d \t %.2lf \t %d \t %.4lf\n", i,sqrt(i), i*i, log(i)); fclose(wfile);}
// method to check if passed number is prime or notint isPrime(int n){ int i; if(n == 2) return 1; for(i=2; i<=(int)(sqrt(n)); i++) if(n%i == 0) return 0; return 1;}
// method to write all primes <10000 in filevoid writePrime(){ FILE *wfile; wfile = fopen("table.txt", "a"); fprintf(wfile, "\n\n"); int count=2, column=0; // for each number while(count <= 10000) { // if it is prime if(isPrime(count) == 1) { // write it to file andincrease column count fprintf(wfile, "%d\t",count); column++; } count++; // if 8 columns reached, go to nextline if(column == 8) { fprintf(wfile,"\n"); column = 0; } } fclose(wfile);}
// driver codeint main(){ ShowHeader(); writeTable(); writePrime();}
IN C++. Can anyone tell me what is wrong with my code? Itcompiles but when trying to run it I get no show of output insteadof what is needed. I'm not too good with this file output stuffyet.
Program Description: Your program is to perform the following operations. 1. Output standard Header Put all of your standard output information into a function named ShowHeader(). 2. Simple Function Table Write a function to generate a table of f(x) for the following functions: sqrt(x)(xn,n=1/2), square (x)(xn,n=2), and log(x). The range of x should be 0 to 10 in steps of 1,10 to 50 in steps of 5 . All output must be in one table generated by a single loop. 3. Prime Number Table Write a function to generate a table of all prime numbers less than 10,000 . The prime number table function will call another function that tests if an integer is prime or (this function will be discussed in class). The table must be printed with eight (8) numbers per line. Deliverables: - Program-fully documented. - Output-Neatly formatted and documented. All output is to be written to a file. - Program design sheet-In addition to your program and the output, attach a page showing a rough design of your program. - Sample calculations for part 2-Neatly formatted and documented. This must be on a separate sheet that is attached to this assignment. Note: Your program design and sample calculations should be done before you start programming.