|
#include <iostream>
using namespace std;
#include "dsqlm.h"
using namespace dsqlm;
int main() {
try {
Database db("weather");
// create a table to store temperatures at different times of a day
db.execute("create table temperatures(id autoid,rec_date date indexed,"
"rec_time time,temp float)");
char sql[101];
float temp;
while(true) {
cout << "Enter temperature (0 to exit): ";
cin >> temp;
if(temp == 0) break;
sprintf(sql,
"insert into temperatures values(0,'sysdate','systime',%.2f)",
temp);
db.execute(sql);
// find out todays average temperature
ResultSet rslt = db.executeQuery("select temp,rec_time from temperatures where rec_date = 'sysdate'");
float tot = 0;
int count = 0;
cout << endl;
while(rslt.next()) {
cout << "Temp: "<<rslt.getString(1)<<"Recorded at: "
<<rslt.getString(2)<<endl;
tot += rslt.getFloat(1);
count++;
}
cout << "Today's average temperature: " << (tot/count) << endl;
}
}catch(DsqlMException ex) {
cout << ex.getMessage();
}
return 1;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.