Assume I have a table. The values inside the table are determined by y and x var
ID: 664405 • Letter: A
Question
Assume I have a table. The values inside the table are determined by y and x variables. But in this case it is t and p (or temperature and pressure). Those values for t and p don't correlate to my array in code ( for example on column = 0 the temperature= -120). That's what a and b are for. I want to be able to input a value between two rows or columns and use a y=mx+b equation to find it.I'm trying to make a linear interpolation from an array code but the functions don't seem to work. Can someone help me?
#include <iomanip>
#include <string>
#include <iostream>
using namespace std;
int main()
{
int a;
int j, i;
float t1, t2, m, p2, p1, w, p,t, a1, a2;
double pt [75][21] = {{...}};
cout << "input temp"<< endl;
cin >> t;
cout << "input the pressure"<< endl;
cin >> p;
for (i=0; i<21; i++);
for (j=0; j<75; j++)
{
if (pt[j][i]>= p)
{
p1=pt[j-1][i];
p2=pt[j][i];
break;
}
}
cout<<"p1 ="< cout<<"p2 ="< for( i = 0; i<75; i++)
for(j= 0; j<21; j++)
{
if(pt[i][j]>=t)
{
a1=pt[i][j-1];
a2=pt[i][j];
break;
}
}
cout<<"t1="< cout<<"t2="< m=(a2-a1)/5;
cout.precision(4);
cout<<"The slope is: "< cin.get();
w=m(t-i)+t1;
cout<<"The answer is = "<
{
if (p == 5)
{
a = 15;
}
if (p==10)
{
a = 16;
}
if (p==15)
{
a = 17;
}
if (p==20)
{
a=18;
}
if (p==25)
{
a=19;
}
if (p==30)
{
a=20;
}
if (p==35)
{
a=21;
}
if (p==40)
{
a=22;
}
if (p==45)
{
a=23;
}
if (p==50)
{
a=24;
}
if (p==55)
{
a=25;
}
if (p==60)
{
a=26;
}
if (p==65)
{
a=27;
}
if (p==70)
{
a=28;
}
if (p==75)
{
a=29;
}
if (p==80)
{
a=30;
}
if (p==85)
{
a=31;
}
if (p==90)
{
a=32;
}
if (p==95)
{
a=33;
}
if (p==100)
{
a=34;
}
if (p==105)
{
a=35;
}
if (p ==110 )
{
a=36;
}
if (p==115)
{
a=37;
}
if (p==120)
{
a=38;
}
if (p==125)
{
a=39;
}
if (p==130)
{
a=40;
}
if (p==135)
{
a=41;
}
if (p==140)
{
a=42;
}
if (p==145)
{
a=43;
}
if (p==150)
{
a=44;
}
if (p==155)
{
a=45;
}
if (p==160)
{
a=46;
}
if (p==165)
{
a=47;
}
if (p==170)
{
a=48;
}
if (p==175)
{
a=49;
}
if (p==180)
{
a=50;
}
if (p==185)
{
a=51;
}
if (p==190)
{
a=52;
}
if (p==195)
{
a=53;
}
if (p==200)
{
a=54;
}
if (p==205)
{
a=55;
}
if (p==210)
{
a=56;
}
if (p==215)
{
a=57;
}
if (p==220)
{
a=58;
}
if (p==225)
{
a=59;
}
if (p==230)
{
a=60;
}
if (p==235)
{
a=61;
}
if (p==240)
{
a=62;
}
if (p==245)
{
a=63;
}
if (p==250)
{
a=64;
}
if (p==255)
{
a=65;
}
if (p==260)
{
a=66;
}
if (p==265)
{
a=67;
}
if (p==270)
{
a=68;
}
if (p==275)
{
a= 69;
}
if (p==280)
{
a=70;
}
if (p==285)
{
a=71;
}
if (p==290)
{
a=72;
}
if (p==295)
{
a=73;
}
if (p==300)
{
a=74;
}
if (p== 1)
{
a = 11;
}
if (p== 2)
{
a = 12;
}
if (p== 3)
{
a = 13;
}
if (p== 4)
{
a = 14;
}
if (p == 1e-1)
{
a = 10;
}
if (p == 1e-2)
{
a = 9;
}
if (p== 1e-3){
a = 8;
}
if (p== 1e-4)
{
a = 7;
}
if (p== 1e-5)
{
a = 6;
}
if (p== 1e-6)
{
a = 5;
}
if (p== 1e-7)
{
a=4;
}
if (p== 1e-8)
{
a=3;
}
if (p== 1e-9)
{
a =2;
}
if (p== 1e-10)
{
a=1;
}
}
b= (120+t)/5;
cout << "the answer is" << pt[a][b]<< endl;
return 0;
}
Explanation / Answer
the above code has issue.
1. array is not defined.
2. there are 5/6 other problems with the code. now fixed
#include <iomanip>
#include <string>
#include <iostream>
using namespace std;
int main()
{
int a;
int j, i;
float t1, t2, m, p2, p1, w, p,t, a1, a2;
double pt [75][21];
cout << "input temp"<< endl;
cin >> t;
cout << "input the pressure"<< endl;
cin >> p;
for (i=0; i<21; i++);
for (j=0; j<75; j++)
{
if (pt[j][i]>= p)
{
p1=pt[j-1][i];
p2=pt[j][i];
break;
}
}
cout<<"p1 ="< cout<<"p2 =";
for( i = 0; i<75; i++)
for(j= 0; j<21; j++)
{
if(pt[i][j]>=t)
{
a1=pt[i][j-1];
a2=pt[i][j];
break;
}
}
int inte;
inte=(a2-a1)/5;
cout<<"t1="<<endl<<"t2="<<inte;
cout.precision(4);
cout<<"The slope is: "<< cin.get();
w=m*(t-i)+t1;
{
if (p == 5)
{
a = 15;
}
if (p==10)
{
a = 16;
}
if (p==15)
{
a = 17;
}
if (p==20)
{
a=18;
}
if (p==25)
{
a=19;
}
if (p==30)
{
a=20;
}
if (p==35)
{
a=21;
}
if (p==40)
{
a=22;
}
if (p==45)
{
a=23;
}
if (p==50)
{
a=24;
}
if (p==55)
{
a=25;
}
if (p==60)
{
a=26;
}
if (p==65)
{
a=27;
}
if (p==70)
{
a=28;
}
if (p==75)
{
a=29;
}
if (p==80)
{
a=30;
}
if (p==85)
{
a=31;
}
if (p==90)
{
a=32;
}
if (p==95)
{
a=33;
}
if (p==100)
{
a=34;
}
if (p==105)
{
a=35;
}
if (p ==110 )
{
a=36;
}
if (p==115)
{
a=37;
}
if (p==120)
{
a=38;
}
if (p==125)
{
a=39;
}
if (p==130)
{
a=40;
}
if (p==135)
{
a=41;
}
if (p==140)
{
a=42;
}
if (p==145)
{
a=43;
}
if (p==150)
{
a=44;
}
if (p==155)
{
a=45;
}
if (p==160)
{
a=46;
}
if (p==165)
{
a=47;
}
if (p==170)
{
a=48;
}
if (p==175)
{
a=49;
}
if (p==180)
{
a=50;
}
if (p==185)
{
a=51;
}
if (p==190)
{
a=52;
}
if (p==195)
{
a=53;
}
if (p==200)
{
a=54;
}
if (p==205)
{
a=55;
}
if (p==210)
{
a=56;
}
if (p==215)
{
a=57;
}
if (p==220)
{
a=58;
}
if (p==225)
{
a=59;
}
if (p==230)
{
a=60;
}
if (p==235)
{
a=61;
}
if (p==240)
{
a=62;
}
if (p==245)
{
a=63;
}
if (p==250)
{
a=64;
}
if (p==255)
{
a=65;
}
if (p==260)
{
a=66;
}
if (p==265)
{
a=67;
}
if (p==270)
{
a=68;
}
if (p==275)
{
a= 69;
}
if (p==280)
{
a=70;
}
if (p==285)
{
a=71;
}
if (p==290)
{
a=72;
}
if (p==295)
{
a=73;
}
if (p==300)
{
a=74;
}
if (p== 1)
{
a = 11;
}
if (p== 2)
{
a = 12;
}
if (p== 3)
{
a = 13;
}
if (p== 4)
{
a = 14;
}
if (p == 1e-1)
{
a = 10;
}
if (p == 1e-2)
{
a = 9;
}
if (p== 1e-3){
a = 8;
}
if (p== 1e-4)
{
a = 7;
}
if (p== 1e-5)
{
a = 6;
}
if (p== 1e-6)
{
a = 5;
}
if (p== 1e-7)
{
a=4;
}
if (p== 1e-8)
{
a=3;
}
if (p== 1e-9)
{
a =2;
}
if (p== 1e-10)
{
a=1;
}
}
int b;
b= (120+t)/5;
cout << "the answer is" << pt[a][b]<< endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.