Advertisement
ndm2018

polynomials

May 26th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #define SIZE 50
  6.  
  7.  
  8.  
  9. int readFile(char array[]);
  10. void menu(char choice,char array[]);
  11.  
  12.  
  13.  
  14. int main(){
  15.    
  16.         char array[SIZE];
  17.         char choice;
  18.         int flag=1;
  19.    
  20.    
  21.    
  22.        
  23.         while(flag){
  24.            
  25.            
  26.                 readFile(array);
  27.    
  28.                 menu(choice,array);
  29.            
  30.                
  31.                 system("CLS");
  32.         }
  33.    
  34.         getch();
  35.    
  36.    
  37.     return 0;
  38.    
  39.    
  40. }
  41.  
  42.  
  43. /* A function that reads the polynomials from file (sample.txt) */
  44.  
  45. /* INSIDE THE sample.txt is:
  46.                              8x^9 + 5x^8 - 5x^6 + 2x^4 - 6x + 10
  47.                              5x^9 - 7x^7 + 18x^6 - 4x^3 - 3x - 15
  48. */
  49.  
  50. int readFile(char array[]){
  51.    
  52.    
  53.    
  54.     int i;
  55.    
  56.     FILE *textFile;
  57.    
  58.     textFile=fopen("sample.txt","r");
  59.    
  60.  
  61.  
  62.     if(textFile !=NULL){
  63.        
  64.        
  65.         while(!feof(textFile)){
  66.            
  67.             fgets(array,50,textFile);
  68.             printf("First polynomial: %s",array);
  69.             fgets(array,50,textFile);
  70.             printf("Second polynomial: %s",array);
  71.         }
  72.         fclose(textFile);
  73.        
  74.        
  75.     }
  76.     else{
  77.        
  78.         printf("error!");
  79.     }
  80.    
  81.    
  82.    
  83.     printf("\n");
  84.    
  85.    
  86. }  
  87.    
  88.  
  89.  
  90. /* just displaying menu and calling other functions */
  91.  
  92. void menu(char choice,char array[]){
  93.    
  94.     int sum=0;
  95.     float average;
  96.    
  97.        
  98.      printf("\n*****************************\n");
  99.      printf("*      [A] Addition         *\n");
  100.      printf("*      [S] Subtraction      *\n");
  101.      printf("*      [D] Derivative       *\n");
  102.      printf("*****************************\n");
  103.      scanf("%c",&choice);
  104.      
  105.    
  106.      
  107.      
  108.     switch(choice)
  109.       {
  110.  
  111.         // i still haven't figure out how to extract the polynomial correctly that's why i can't make the functions
  112.         case 'A':
  113.            
  114.             //polyaddition();
  115.             getch();
  116.             break;
  117.        
  118.         case 'S':
  119.        
  120.             //polysubtraction();
  121.             getch();
  122.             break;
  123.      
  124.      
  125.         case 'D':
  126.            
  127.             //firstpolyderivative();
  128.             //secondpolyderivative();
  129.             getch();
  130.             break;
  131.      
  132.      }
  133.      
  134.      getch();
  135.    
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement