Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <string>
- using namespace std;
- int serial=1;
- struct table{
- char varName[100];
- char varType[100];
- char varValue[100];
- bool dlt = false;
- };
- struct table st[100];
- char varName[100];
- char varType[100];
- //char varValue[100];
- void insert();
- void varNamsearch();
- void showall();
- void showSpec();
- int findSerial();
- int main() {
- bool decision = true;
- while(decision){
- cout<<endl<<"1. Insert :\n";
- cout<<"2. Delete :\n";
- cout<<"3. Show specefic :\n";
- cout<<"4. Show all :\n";
- cout<<"5. Update :\n"<<endl;
- string n;
- cin>>n;
- if(n == "1" ){
- insert();
- }
- else if(n == "2"){
- }
- else if(n == "3"){
- showSpec();
- }
- else if(n == "4"){
- showall();
- }
- else{
- cout<<"Invalid input, enter again \n";
- }
- }
- return 0;
- }
- void insert(){
- cin.ignore();
- string input;
- getline(cin, input);
- int findEqual;
- findEqual = input.find('=');
- int splt=0;
- int n=0;
- if(findEqual == -1) {
- for (int i = 0; '\0' != input[i]; ++i) {
- // cout<<"first"<<endl;
- if (splt == 0) {
- if (input[i] == ' ') {
- st[serial].varType[n] = '\0';
- } else {
- st[serial].varType[n] = input[i];
- n++;
- }
- }
- if (splt == 1) {
- if (input[i] == ';') {
- st[serial].varName[n] = '\0';
- } else {
- st[serial].varName[n] = input[i];
- n++;
- }
- }
- if (input[i] == ' ') {
- splt++;
- n = 0;
- }
- }
- st[serial].varValue[0] ='N';
- st[serial].varValue[1] ='U';
- st[serial].varValue[2] ='L';
- st[serial].varValue[3] ='L';
- st[serial].varValue[4] ='\0';
- serial++;
- } else{ // for float amount=2.25
- //cout<<"second"<<endl;
- for (int i = 0; '\0' != input[i]; ++i) {
- if (splt == 0) {
- if (input[i] == ' ') {
- st[serial].varType[n] = '\0';
- } else {
- st[serial].varType[n] = input[i];
- n++;
- }
- }
- if (splt == 1) {
- if (input[i] == '=') {
- st[serial].varName[n] = '\0';
- } else {
- st[serial].varName[n] = input[i];
- n++;
- }
- }
- if(splt == 2){
- if (input[i] == ';') {
- st[serial].varValue[n] = '\0';
- } else {
- st[serial].varValue[n] = input[i];
- n++;
- }
- }
- if (input[i] == '=' || input[i] == ' ') {
- splt++;
- n = 0;
- }
- }
- serial++;
- }
- }
- void varNamsearch(){
- int a;
- string input;
- getline(cin, input);
- int start = input.find(' ', 0)+1;
- int i;
- int j=0;
- for ( i= start; i<input.length(); i++) {
- if(input[i]== '=' || input[i] == ';'){
- break;
- }
- else{
- varName[j] = input[i];
- j++;
- //cout<<input[i];
- };
- }
- varName[j] = '\0';
- cout<<varName;
- }
- void showall(){
- for (int i = 1; i <serial; ++i) {
- cout<<i<<" "<<st[i].varName<<" "<<st[i].varType<<" "<<st[i].varValue<<endl;
- }
- }
- void showSpec(){
- int id = findSerial();
- if (id == -1){
- cout<<" Name not found"<<endl;
- } else {
- cout << id << " " << st[id].varName << " " << st[id].varType << " " << st[id].varValue << endl;
- }
- }
- int findSerial(){
- string input;
- cin>>input;
- char x[100];
- int j;
- for (j = 0; j <input.length(); ++j) {
- x[j] = input[j];
- }
- x[j] = '\0';
- for (int i = 1; i <serial ; ++i) {
- if(strcmp(st[i].varName, x) == 0)
- return i;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement