assign6.c - Sheet1 Page 1

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sheet1 Page 1 /******************************************************** * Name:Arria P. Owlia * EID:apo223 * Course:15735 * Assignment:6 * Purpose:To become familiar with linked lists and * fun with polynomials. *********************************************************/ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> int getPolyNum(char a) char isAvailable(char a) int* store(char a, int *b) char printFile(char a, int numPoly) void add(int *a, int b, int c) void multiply(int *a, int b, int c) void evaluate(int *arr, int polynum, float val) void printNew(struct node *a) void clearMem(int *a, int numPoly) struct node/*set node parameters*/ { float coeff int power struct node *next } int main() { char filename[200], choice1, choice2 = 'Y', choice3 = 'Y' int *a = NULL, input1, input2, numPoly = 0, read = 0 while(choice3 == 'Y' || choice3 == 'y') { printf("Input the name of the polynomial file: ") scanf("%s", filename) choice2 = isAvailable(filename) while (choice2 == 'Y' || choice2 == 'y') { if (read == 0) { numPoly = getPolyNum(filename) printf("\nThe polynomials available for operation are:\n\n") a = store(filename, a) if (a == NULL) return(1) printFile(filename, numPoly) read = 1 } Sheet1 Page 2 printf("What operation would you like to perform?\n1. ADD polynomials\n2. MULTIPLY polynomials\n3. EVALUATE polynomia scanf(" %c", &choice1) choice1 = choice1 - '0' switch(choice1) { case 1:/*get user input and execute add function*/ { printf("Input the polynomials to be added [p1, p2]: ") scanf("%d%*c%d", &input1, &input2) if (input1 <= numPoly && input2 <= numPoly) add(a, input1, input2) else printf("Illegal Entry...\n") break } case 2:/*get user input and execute multiply function*/ { printf("Input the polynomials to be multiplied [p1,p2]: ") scanf("%d%*c%d", &input1, &input2) if (input1 <= numPoly && input2 <= numPoly) multiply(a, input1, input2) else printf("Illegal Entry...\n") break } case 3:/*get user input and execute evaluate function*/ { int poly = 0 float eval = 0 printf("Input the polynomial to be evaluated [p1]: ") scanf("%d", &poly) printf("Input the value of x: ") scanf("%f", &eval) if (poly <= numPoly) evaluate(a, poly, eval) else printf("Illegal Entry...\n") break } case 4: { break } default: { printf("Invalid Input. Please re-enter...\n") } } if (choice1 != 4) { printf("Do you want to perform additional operations on this file (Y/N)?\n") scanf(" %c", &choice2) Sheet1...
View Full Document

Page1 / 27

assign6.c - Sheet1 Page 1

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online