Hello fellow members,
I know there are million others who are out of ideas to code, like me. After a little bit of searching, I have found a link in which it contains some C++ exercises and solutions for those exercises. Remember that the exercises are arranged from difficulty; If you want the hard ones, scroll all the way to the bottom.
Ordered based on difficulty(really easy for beginner programmers): http://en.wikibooks.org/wiki/C++_Program...Iterations
A lot of exercises!: http://en.wikibooks.org/wiki/C%2B%2B_Pro.../Exercises
Not ordered in any way: http://www.fz-juelich.de/video/cpp/html/exercises.html
The most famous, ProjectEuler: http://projecteuler.net/index.php?section=problems
I hope you found this helpful. Please if you have any ideas or websites which contains some programming ideas, feel free to post them.
Thanks for reading,
Showing posts with label database. Show all posts
Showing posts with label database. Show all posts
Sunday, September 8, 2013
Sunday, September 1, 2013
Dynamic Database - ProjectEuler + Solution
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:
I know this source code sucks, leave me alone:
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:
Spoiler (Click to View)
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;
}
Subscribe to:
Posts (Atom)