鸟类调查中的项目在代码中遇到问题.如何像数据库系统一样存储数据
Projet in birds survey having trouble in code. how to store data like database system
如何将我的输入存储在以下类别中,即水,家庭等。当我提供有关水鸟的信息时,我提供有关家禽的信息,但第二个信息覆盖了第一个信息。有没有办法存储类别方面的数据?
/* declaring header files */
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include <fstream>
#include <bits/stdc++.h>
#include <string>
using namespace std;
class Bird{
private:
char name[50],colour[50],nature[50],location[50];
float living_duration;
public:
int code;
int set_info(){
char name=' ';
char colour=' ';
char nature=' ';
char location=' ';
float living_duration=0.0;
}
int get_info(){
cout<<"nEnter bird's name: ";
cin>>name;
cout<<"Colour: ";
cin>>colour;
cout<<"Nature: ";
cin>>nature;
cout<<"Location: ";
cin>>location;
cout<<"Living Duration: ";
cin>>living_duration;
cout<<"Bird's code: ";
cin>>code;
}
int display_info(){
cout<<"nBird's name: "<<name;
cout<<"nColour : "<<colour;
cout<<"nNature : "<<nature;
cout<<"nlocation : "<<location;
cout<<"nLiving Duration : "<<living_duration<<" year";
cout<<"nCode : "<<code;
}
}obj[100];
int main(){
int i,j,k,n,m;
do{
cout<<"nnWhat do you want to don1.Input bird's information"
<<"n2.Displayn3.Searchn4.Exit."
<<"nnChoose appropriate number: ";
cin>>n;
switch(n){
case 1://bird information
cout<<"Please Select Birds Category"<<endl;
cout<<"------------------"<<endl;
cout<<"1)Watern2)Domesticn3)preyn4)treebasedn5)flightlessn6)migratoryn"<<endl;
cin>>m;
switch(m){
case 1:
cout<<"Enter the number of bird how many to input: ";
cin>>j;
for(i=1;i<=j;i++){
cout<<"nInformation of Bird "<<i<<".n";
obj[i].get_info();
}
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
default:
cout<<"Wrong choice!!nPlease enter correct number.";
break;
}
case 2://display
for(i=1;i<=j;i++)
{
cout<<"nBird no "<<i<<".n";
obj[i].display_info();
cout<<"n";
}
break;
case 3://search
cout<<"nEnter the bird code: ";
cin>>k;
for(i=1;i<=j;i++)
{
if(k==obj[i].code)
{
cout<<"nBird no "<<i<<".n";
obj[i].display_info();
break;
}
}
if(k!=obj[i].code)
cout<<"Wrong code input...n";
break;
case 4://exit
break;
default:
cout<<"Wrong choice!!nPlease enter correct number.";
break;
}
}while(n!=4);
}
您需要在鸟类
数据和数据容器之间拆分概念。
在关系数据库中,您将拥有表。 让表的列由结构的数据成员表示。 表的记录(行)将是记录结构的实例:
class Bird
{
public:
std::string name;
std::string colour;
std::string nature;
std::string location;
float living_duration;
};
对于容器或表,您可以使用std::vector
:
std::vector<Bird> bird_table;
许多关系数据库还包括索引表以加快搜索速度。 索引表将包含对、键(或列值)和索引到std::vector
。 C++语言有一个方便的容器,称为std::map
:
std::map<string, unsigned int> name_index;
string
参数表示键或列类型。unsigned int
参数表示数据库的索引(也称为外键)。
要按名称检索 Bird 记录,请先访问索引表,然后访问向量:
unsigned int database_index = name_index["crow"];
Bird crow = database[index];
相关文章:
- C++,系统无法执行指定的程序
- 查询SQLite数据库中的日期
- 在UNIX系统中使用DIR查找文件的字节大小
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- LMDB:在有限的内存系统中打开大型数据库
- 如何保护系统和数据库之间的密码
- 访问另一个类(系统)的非静态字段,就好像它是我自己的字段一样 - 优雅地
- 如何在文件系统之上添加层?就像OneDrive或Google云端硬盘中的缓存一样
- 鸟类调查中的项目在代码中遇到问题.如何像数据库系统一样存储数据
- 像C++一样编写高效的实体系统
- 有没有办法像系统("pause")一样暂停?
- 使用系统时间的随机数都是一样的
- 如何将sql数据库文件从系统位置复制到另一个位置
- 我能否像在PythonQt中一样利用PyQt中的Qt Meta-Object系统?
- 如何创建文件路径可以像磁盘一样访问的虚拟文件系统
- QT C++ 将文件从数据库存储到我的文件系统
- 数据库或文件系统访问的const语义
- 我应该使用文件系统还是数据库来存储我的数据在我的音乐识别应用程序
- 是否存在轻量级和无需安装的数据库系统
- 轻量级的c++数据库系统