-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
146 lines (134 loc) · 4.84 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include<iomanip>
#include<math.h>
#include<cmath>
#define no_of_fraction_digits 3
using namespace std;
int number(float,bool);
int main()
{
int div[2];
float data[2][20],maxn[2],minn[2];
cout<<"Enter Max Value in X ";
cin>>maxn[0];
cout<<"Enter Max Value in Y ";
cin>>maxn[1];
cout<<"Enter Min Value in X ";
cin>>minn[0];
cout<<"Enter Min Value in Y ";
cin>>minn[1];
cout<<"Enter the Number of Divisions in X ";
cin>>div[0];
cout<<"Enter the Number of Divisions in Y ";
cin>>div[1];
if(minn[0]!=0)
div[0]--;
if(minn[1]!=0)
div[1]--;
float new_max[]={maxn[0]-minn[0],maxn[1]-minn[1]};
// cout<<new_max[0]<<endl<<" "<<new_max[1];
//cout<<number((new_max[0])/div[0],1);
//return 0;
while(number((new_max[0])/div[0],1)>no_of_fraction_digits){
new_max[0]+=(1/(pow(10,no_of_fraction_digits)));
// cout<<"Next :"<<new_max[0]<<endl;
}
//cout<<new_max[0]<<endl<<" "<<new_max[1];
while(number((new_max[1])/div[1],1)>no_of_fraction_digits){
new_max[1]+=(1/(pow(10,no_of_fraction_digits)));
// cout<<"Next :"<<new_max[1]<<endl;
}
//cout<<new_max[0]<<endl<<new_max[1]<<endl;
cout<<endl<<"---------------------------"<<endl;
cout<<"Scale \nX-axis\t"<<(maxn[0]/div[0])<<"\nY-axis\t"<<(maxn[1]/div[1])<<endl;
cout<<endl<<"---------------------------"<<endl;
maxn[0]=new_max[0];
maxn[1]=new_max[1];
cout<<endl<<"Scale for X is"<<endl;
for(int i=0;i<div[0]+1;i++){
cout<<((maxn[0]/div[0])*i)+minn[0]<<endl;
}
cout<<endl<<"---------------------------"<<endl;
cout<<"Scale for Y is"<<endl;
for(int i=0;i<div[1]+1;i++){
cout<<((maxn[1]/div[1])*i)+minn[1]<<endl;
}
float con[]={(maxn[0]/(div[0]*10)),(maxn[1]/(div[1]*10))};
cout<<endl<<"---------------------------"<<endl;
cout<<"Enter the Number of Graphs ";
int h;
cin>>h;
cout<<endl<<"---------------------------"<<endl;
cout<<"Enter the Number of Values ";
int val;
cin>>val;
cout<<endl<<"---------------------------"<<endl;
bool ask=false;
char r;
int extra[]={0,0};
for(int u=0;u<h;u++){
ask=false;
if(u>=1){
cout<<endl<<"Do you want same values of X? "<<endl;
cin>>r;
if(r=='y'||r=='Y'){
ask=true;
}
}
for(int i=0;i<val;i++){
cout<<"Enter Value in the following format \" x (space) y \" ";
if(ask!=true)
cin>>data[0][i];
cin>>data[1][i];
cout<<endl;
}
if(minn[0]!=0){
extra[0]=10;
}
if(minn[1]!=0){
extra[1]=10;
}
cout<<"The (x,y) pairs are (count of the subdivisions on the Graph Paper) :"<<endl;
for(int i=0;i<val;i++){
cout<<" "<<((data[0][i]-minn[0])/con[0])+(extra[0])<<" , "<<((data[1][i]-minn[1])/con[1])+(extra[1])<<endl;
}
}
}
int number(float val,bool frac=0){
int numb=0,tempi=(int)val,valn;
bool rep[]={false,false};
float temp=val;
if((modf(temp,nullptr)*1000)!=0){
for(int i; (temp!=0);i++){
temp*=10;
numb++;
//cout<<"Before modf "<<temp<<endl;
temp=modf(temp,nullptr);
//cout<<"Fraction "<<temp<<endl;
if(rep[1]==true)
break;
for(int y=1;y<9;y++){
valn=(100*y)+(10*y)+y;
if((int)(temp*1000)==valn){
if(rep[0]==true)
rep[1]=true;
rep[0]=true;
}
}
if((int)(temp*1000)==999||(int)(temp*1000)==0){
break;
}
}
}
if(frac == true) // return number of fraction digits
return numb;
//cout<<"Count of Fraction Number"<<numb<<endl;
if(tempi!=0){
while(tempi!=0){
tempi/=10;
numb++;
}
}
//cout<<"no_of_fraction_digits"<<numb<<endl;
return numb;
}