Hello fellow members,
Before you talk about SQL connection and stuff, this has nothing to do with that.
My friend gave me an assignment to do this:
Code:
Make a program like this:
1. Add to database
2. Display databse
Option:
You should be able to add as many databases as you want. It should ask you for name, age, gender, and after it is registered, put the computer time in a string(which should be a string or whatever). All this information should be taken into a structure
When displaying the database, it should display like this:
--
<The registered time>
Name: Name
Age: 15
Gender: M
The 'Display database' option should print all the databases added.
I know this source code sucks, leave me alone:
Code:
#include <iostream>
#include <string>
#include <ctime>
int counter = 0, option = 0;
struct data_base
{
std::string name;
int age;
char gender;
std::string curtime;
};
int main()
{
data_base **array = new data_base*;
data_base *data = new data_base;
while(1)
{
system("CLS"); //don't care
std::cout << "1. Append to Database\n2. Display Database\nChoose(1/2):";
std::cin >> option;
if(option == 1)
{
data = new data_base;
system("CLS"); //don't care
std::cout << "Enter the name: ";
std::cin.ignore();
std::getline(std::cin, data->name);
std::cout << "Enter the Age: ";
std::cin >> data->age;
std::cout << "Enter the gender: ";
std::cin >> data->gender;
while(data->gender != 'm' && data->gender != 'M' && data->gender != 'f' && data->gender != 'F')
{
std::cout << "\nEnter the correct gender type\n";
std::cout << "Enter the gender: ";
std::cin >> data->gender;
}
time_t raw_time;
tm *time_info;
time(&raw_time);
time_info = localtime(&raw_time);
data->curtime = asctime(time_info);
array[counter] = data;
counter++;
}
else if(option == 2)
{
system("CLS"); //don't care
int c = 0;
while(c < counter) //problem is heere
{
std::cout << "\n--\n";
std::cout << "Time appended: " << array[c]->curtime << std::endl;
std::cout << "Name: " << array[c]->name << std::endl;
std::cout << "Age: " << array[c]->age << std::endl;
std::cout << "Gender: " << array[c]->gender << std::endl;
c++;
}
std::cin.ignore();
std::cin.get();
}
else
{
std::cout << "Can you read?";
}
}
std::cin.ignore();
std::cin.get();
return 0;
}
No comments:
Post a Comment