Advertisement
sevn35

Graphing calc

Oct 17th, 2022 (edited)
1,173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. /*
  2. This program creates a basic graph using whole numbers. maxX sets the largest x value and has y adjust according to it. The function may be changed in the formula function. Possible improvments include allowing user to change function from input, allowing decimal numbers, and negative quadrants.
  3. */
  4.  
  5. #include <iostream>
  6. #include <cmath>
  7. #include <string>
  8. #include <iomanip>
  9. using namespace std;
  10.  
  11. int digit(int number) {
  12.     //This function gathers digits to set width of y numb line
  13.     int count = 0;
  14.     while(number != 0) {
  15.         number = number / 10;
  16.         count++;
  17.     }
  18.     return count;
  19. }
  20.  
  21. int formula(int x){
  22.     //this function serves to update maxY and f(x) using only one value
  23.     return pow(x,2);
  24.    
  25. }
  26.  
  27. int main() {
  28.     int maxX= 5;
  29.     int maxY=formula(maxX);
  30.     for(int y=0; y<=maxY; y++){
  31.         cout << setw(digit(maxY)) << maxY-y;
  32.         for(int x=0; x<=maxX; x++){
  33.             if(formula(x)==(maxY-y)){
  34.                 cout << "o";
  35.             }
  36.             else
  37.                 cout << " ";
  38.         }
  39.         cout << endl;
  40.     }
  41.     return 0;
  42. }
Tags: C++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement