这段代码只是第一版,以后会逐渐迭代.直至能在安卓上运行为止.
我懒得分.h和main.cpp了.
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
int count_Train = 0;
int count_Data = 0;
int count_Run = 0;
const int MAXTrain = 1000;
const int MAXData = 100;
const int MAXRun = 100;
bool flag = true;
class Base
{
public:
virtual void read() = 0;
virtual void add() = 0;
virtual void del(int) = 0;
virtual void fix(int) = 0;
virtual void save() = 0;
};
//-------------------------------------------------------------------
class Train :public Base
{
public:
string name;
int rep;//次数
int set;//组数
double weight;//哑铃重量
double Vol() { return rep * set * weight; }
void read();
void add();
void del(int);
void fix(int);
void save();
};
Train t1[MAXTrain];
void Train::read()
{
fstream trainfile("锻炼日志.txt", ios::in | ios::out);
while (!trainfile.eof())
{
trainfile >> t1[count_Train].name >> t1[count_Train].weight>> t1[count_Train].set>> t1[count_Train].rep;
count_Train++;
}//while语句对于for语句的优点在于不必考虑具体要循环几次。
trainfile.close();
}
void Train::add()//存入对象数组
{
t1[count_Train - 1].name = name;
t1[count_Train - 1].weight = weight;
t1[count_Train - 1].set = set;
t1[count_Train - 1].rep = rep;
}
void Train::del(int index)
{
for (int i = index; i <= count_Train - 1; i++)
{
t1[i - 1].name= t1[i].name;
t1[i - 1].weight= t1[i].weight;
t1[i - 1].set = t1[i].set;
t1[i - 1].rep = t1[i].rep;
}
count_Train--;
}
void Train::fix(int index)
{
t1[index - 1].name = name;
t1[index - 1].weight = weight;
t1[index -