C language please: A math teacher needs to quiz students about solving the quadr
ID: 3749891 • Letter: C
Question
C language please: A math teacher needs to quiz students about solving the quadratic formula. She has a very large class and is worried about cheating, so she wants to give each student a randomized quiz to solve. The quiz will contain 3 quadratic problems: one with repeated roots, one with real roots, and one with complex roots. In each case, the roots will have the following restrictions: Example: Quiz #1: 1. Solve for the roots: x2+ 4x +3-0 2. Solve for the roots: x2+7x-2- 3, Solve for the roots: x2 + 4-0 Solutions for Quiz #1 : The Quadratic Equation September 16,2018 Repeated roots: In the range -5 to 5, but cannot be 0. Real roots: Both in the range-5 to 5; the first root cannot be 0, the second cannot be the same as the first 1. Solve for the rooks: +4r +30 to 5; the imaginary part cannot be 0. Create a program that generates two text files: Discriminant The quiz questions (for the student) b) The answer key (for the teacher) please use this functions 42-4.1.3-16-12.4 d>0: Real Roots char strl) + void getRealReootsQ(char stxl); void getComplexRootsQ(char strl)Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
FILE * fp1;
FILE * fp2;
int i;
int lower = -5, upper = 5, count = 7;
int roots[7];
// Using current time as seed for random number generation
srand(time(0));
int num;
for (i = 0; i < count; i++) {
num = (rand()%(upper - lower + 1)) + lower;
if(num==0 || (i==2 && roots[1]==roots[2])){
i--;
continue;
}
else{
roots[i]=num;
}
}
/* open the file for writing*/
fp1 = fopen ("Quadratic questions.txt","w");
fp2 = fopen ("Quadratic solutions.txt","w");
fprintf (fp1, "Q1) x^2 +%d*x +%d ",-2*roots[0],roots[0]*roots[0]);
fprintf (fp2, "A1) Roots are %d,%d ",roots[0],roots[0]);
fprintf (fp1, "Q2) x^2 +%d*x +%d ",-1*(roots[1]+roots[2]),roots[1]*roots[2]);
fprintf (fp2, "A1) Roots are %d,%d ",roots[1],roots[2]);
fprintf (fp1, "Q3) x^2 +(%d+%dj)*x +%d +%dj ",-1*(roots[3]+roots[5]),-1*(roots[4]+roots[6]),roots[3]*roots[5]-roots[4]*roots[6],roots[3]*roots[6]+roots[4]*roots[5]);
fprintf (fp2, "A1) Roots are %d+%dj,%d+%dj ",roots[3],roots[4],roots[5],roots[6]);
/* close the file*/
fclose (fp1);
fclose (fp2);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.