· 8 years ago · Apr 16, 2018, 10:44 AM
1MAIN
2
3// g++ FinalMain.cpp FinalImp.cpp SQLUtil.cpp -l sqlite3 -o objectTest -Wall -std=c++11
4
5#include "def.h"
6#include "SQLUtil.h"
7#include <iostream>
8#include <cmath>
9#include <ctime>
10#include <cstdlib>
11#include <string>
12#include <sqlite3.h>
13
14using namespace std;
15
16int main()
17{
18 sqlutilc();
19 def fi;
20
21
22 sqlutilc sObj;
23
24 fi.getData();
25 fi.math();
26 fi.Zodif();
27 fi.getStats();
28 fi.printResults();
29
30
31
32
33 sObj.callback(void*,int,char**,char**);
34 sObj.insertData(day, personality, zodiac, chinese, intel, emo, phy, intu, spi, awa, aes);
35 sObj.executeSQL(char*);
36 sObj.closeDB();
37
38 return 0;
39}
40
41
42
43
44
45
46IMP
47
48
49
50
51
52
53
54
55#include "def.h"
56#include <iostream>
57#include <cmath>
58#include <ctime>
59#include <cstdlib>
60#include <string>
61
62
63using namespace std;
64
65void def::getData()
66{
67 cout << "Enter your name: " << endl;
68 cin >> name;
69 cout << "Enter your birth Year: " << endl;
70 cin >> Byear;
71 cout << "Enter your birth month: " << endl;
72 cin >> Bmonth;
73 cout << "Enter your birth day: " << endl;
74 cin >> Bday;
75}
76
77void def::math()
78{
79 sum = Byear + Bmonth + Bday;
80 bnum = ((( sum - 1 ) % 9 ) + 1);
81
82 chyr = (((Byear - 1900) % 12) + 1 );
83
84 currentTime = time(0);
85 currentDay = currentTime / 86400;
86
87 Ayear = Byear - 1970;
88 Amonth = Bmonth - 1;
89 Aday = Ayear * 365.25;
90 AAday = Amonth * 30.42;
91 AAAday = Bday - 1;
92 Aday = Aday + AAday + AAAday;
93
94 day = currentDay - Aday;
95 day = day;
96
97 phy = sin((2 * PI * day) / 23);
98 emo = sin((2 * PI * day) / 28);
99 intel = sin((2 * PI * day) / 33);
100 intu = sin((2 * PI * day) / 38);
101 spi = sin((2 * PI * day) / 53);
102 awa = sin((2 * PI * day) / 48);
103 aes = sin((2 * PI * day) / 43);
104
105}
106
107
108void def::Zodif()
109{
110
111 if ((Bday>=20 && Bday<=31 && Bmonth==1)||(Bday<=18 && Bday>=1 && Bmonth==2)){
112 zodSign = 1;
113 }
114 else if ((Bday>=19 && Bday<=31 && Bmonth==2)||(Bday<=20 && Bday>=1 && Bmonth==3)) {
115 zodSign = 2;
116 }
117 else if ((Bday>=21 && Bday<=31 && Bmonth==3)||(Bday<=19 && Bday>=1 && Bmonth==4)) {
118 zodSign = 3;
119 }
120 else if ((Bday>=20 && Bday<=31 && Bmonth==4)||(Bday<=20 && Bday>=1 && Bmonth==5)) {
121 zodSign = 4;
122 }
123 else if ((Bday>=21 && Bday<=31 && Bmonth==5)||(Bday<=20 && Bday>=1 && Bmonth==6)) {
124 zodSign = 5;
125 }
126 else if ((Bday>=21 && Bday<=31 && Bmonth==6)||(Bday<=22 && Bday>=1 && Bmonth==7)) {
127 zodSign = 6;
128 }
129 else if ((Bday>=23 && Bday<=31 && Bmonth==7)||(Bday<=22 && Bday>=1 && Bmonth==8)) {
130 zodSign = 7;
131 }
132 else if ((Bday>=23 && Bday<=31 && Bmonth==8)||(Bday<=22 && Bday>=1 && Bmonth==9)) {
133 zodSign = 8;
134 }
135 else if ((Bday>=23 && Bday<=31 && Bmonth==9)||(Bday<=22 && Bday>=1 && Bmonth==10)) {
136 zodSign = 9;
137 }
138 else if ((Bday>=23 && Bday<=31 && Bmonth==10)||(Bday<=21 && Bday>=1 && Bmonth==11)) {
139 zodSign = 10;
140 }
141 else if ((Bday>=22 && Bday<=31 && Bmonth==11)||(Bday<=21 && Bday>=1 && Bmonth==12)) {
142 zodSign = 11;
143 }
144 else if ((Bday>=22 && Bday<=31 && Bmonth==12)||(Bday<=19 && Bday>=1 && Bmonth==1)) {
145 zodSign = 12;
146 }
147 else {
148 cout<<"Invalid Date"<<endl;
149
150 }
151}
152
153
154void def::printResults()
155{
156 cout << endl << "Hello " << name << ", your birth number is ... " << bnum << endl;
157 cout << endl << "You have been alive for " << day << " days" << endl;
158 cout << endl <<"Your personality type is " << personality << endl;
159 cout << endl << "Your Zodiac Sign and description is " << zodiac << endl;
160 cout << endl << "Your Chinese animal is " << chinese << endl;
161 cout << endl << "Your main biorhythm results are as follows: "<< endl;
162 cout << "Physical: " << phy * 100 << "%" << endl << "Emotional: " << emo * 100 << "%" << endl;
163 cout << "Intellectual: " << intel * 100 << "%" << endl << endl << "Your extra results are: " << endl;
164 cout << "Intuition: " << intu * 100 << "%" << endl << "Spiritual: " << spi * 100 << "%" << endl;
165 cout << "Awareness: " << awa * 100 << "%" << endl << "Aesthetic: " << aes * 100 << "%" << endl;
166
167 phy = phy * 100;
168 emo = emo * 100;
169 intel = intel * 100;
170 intu = intu * 100;
171 spi = spi * 100;
172 awa = awa * 100;
173 aes = aes * 100;
174
175}
176
177void def::getStats()
178{
179 cout << endl<< endl;
180
181 if (chyr == 1){
182 chinese = "Rat 1 - quick-witted, smart, charming, and persuasive ";
183 }
184 else if (chyr == 2){
185 chinese = "Ox 2- patient, kind, stubborn, and conservative ";
186 }
187 else if (chyr == 3){
188 chinese = "Tiger 3 - authoritative, emotional, courageous, and intense ";
189 }
190 else if (chyr == 4){
191 chinese = "Rabbit 4 - popular, compassionate, and sincere ";
192 }
193 else if (chyr == 5){
194 chinese = "Dragon 5 - energetic, fearless, warm-hearted, and charismatic ";
195 }
196 else if (chyr == 6){
197 chinese = "Snake 6 - charming, gregarious, introverted, generous, and smart ";
198 }
199 else if (chyr == 7){
200 chinese = "Horse 7 - energetic, independent, impatient, and enjoy traveling ";
201 }
202 else if (chyr == 8){
203 chinese = "Sheep/Goat 8 - mild-mannered, shy, kind, and peace-loving ";
204 }
205 else if (chyr == 9){
206 chinese = "Monkey 9 - fun, energetic, and active ";
207 }
208 else if (chyr == 10){
209 chinese = "Rooster 10 - independent, practical, hard-working, and observant ";
210 }
211 else if (chyr == 11){
212 chinese = "Dog 11 - patient, diligent, generous, faithful, and kind ";
213 }
214 else if(chyr == 12){
215 chinese = "Pig 12 - loving, tolerant, honest, and appreciative of luxury ";
216
217 }
218
219 cout << endl<< endl;
220
221
222 if (bnum == 1){
223 personality = "THE ORIGINATOR 1's are originals. Coming up with new ideas and executing them is natural. Having things their own way is another trait that gets them as being stubborn and arrogant. 1's are extremely honest and do well to learn some diplomacy skills. They like to take the initiative and are often leaders or bosses, as they like to be the best. Being self-employed is definitely helpful for them. Lesson to learn: Others' ideas might be just as good or better and to stay open minded. Famous 1's: Tom Hanks, Robert Redford, Hulk Hogan, Carol Burnett, Wynona Judd, Nancy Reagan, Raquel Welch.";
224 }
225 else if (bnum == 2){
226 personality = "Your personality type is HE PEACEMAKER 2's are the born diplomats. They are aware of others' needs and moods and often think of others before themselves. Naturally analytical and very intuitive they don't like to be alone. Friendship and companionship is very important and can lead them to be successful in life, but on the other hand they'd rather be alone than in an uncomfortable relationship. Being naturally shy they should learn to boost their self-esteem and express themselves freely and seize the moment and not put things off. Famous 2's: President Bill Clinton, Madonna, Whoopee Goldberg, Thomas Edison, Wolfgang Amadeus Mozart.";
227 }
228 else if (bnum == 3){
229 personality = "Your personality type is THE LIFE OF THE PARTY 3's are idealists. They are very creative, social, charming, romantic, and easygoing. They start many things, but don't always see them through. They like others to be happy and go to great lengths to achieve it. They are very popular and idealistic. They should learn to see the world from a more realistic point of view. Famous 3's: Alan Alder, Ann Landers, Bill Cosby, Melanie Griffith, Salvador Dali, Jodi Foster.";
230 }
231 else if (bnum == 4){
232 personality = "Your personality type is THE CONSERVATIVE 4's are sensible and traditional. They like order and routine. They only act when they fully understand what they are expected to do. They like getting their hands dirty and working hard. They are attracted to the outdoors and feel an affinity with nature. They are prepared to wait and can be stubborn and persistent. They should learn to be more flexible and to be nice to themselves. Famous 4's: Neil Diamond, Margaret Thatcher, Arnold Schwarzenegger, Tina Turner, Paul Hogan, Oprah Winfrey.";
233 }
234 else if (bnum == 5){
235 personality = "Your personality type is THE NONCONFORMIST 5's are the explorers. Their natural curiosity, risk taking, and enthusiasm often land them in hot water. They need diversity, and don't like to be stuck in a rut. The whole world is their school and they see a learning possibility in every situation. The questions never stop. They are well advised to look before they take action and make sure they have all the facts before jumping to conclusions. Famous 5's: Abraham Lincoln, Charlotte Bronte, Jessica Walter, Vincent Van Gogh, Bette Midler, Helen Keller and Mark Hail.";
236 }
237 else if (bnum == 6){
238 personality = "Your personality type is THE ROMANTIC 6's are idealistic and need to feel useful to be happy. A strong family connection is important to them. Their actions influence their decisions. They have a strong urge to take care of others and to help. They are very loyal and make great teachers. They like art or music. They make loyal friends who take the friendship seriously. 6's should learn to differentiate between what they can change and what they cannot. Famous 6's: Albert Einstein, Jane Seymour, John Denver, Meryl Streep, Christopher Columbus, Goldie Hawn. ";
239 }
240 else if (bnum == 7){
241 personality = "Your personality type is THE INTELLECTUAL 7's are the searchers. Always probing for hidden information, they find it difficult to accept things at face value. Emotions don't sway their decisions. Questioning everything in life, they don't like to be questioned themselves. They're never off to a fast start, and their motto is slow and steady wins the race. They come across as philosophers and being very knowledgeable, and sometimes as loners. They are technically inclined and make great researchers uncovering information. They like secrets. They live in their own world and should learn what is acceptable and what is not in the world at large. Famous 7's: William Shakespeare, Lucille Ball, Michael Jackson, Joan Baez, Princess Diana. ";
242 }
243 else if (bnum == 8){
244 personality = "Your personality type is THE BIG SHOT 8's are the problem solvers. They are professional, blunt and to the point, have good judgment and are decisive. They have grand plans and like to live the good life. They take charge of people They viewpeople objectively. They let you know in no uncertain terms that they are the boss! They should learn to exude their decisions on their own needs rather than on what others want. Famous 8's: Edgar Cayce, Barbara Streisand, George Harrison, Jane Fonda, Pablo Picasso, Aretha Franklin, Nostrodamus. ";
245 }
246 else if (bnum == 9){
247 personality = "Your personality type is THE PERFORMER 9's are natural entertainers. They are very caring and generous, giving away their last dollar to help. With their charm, they have no problem making friends and nobody is a stranger to them. They have so many different personalities that people around them have a hard time understanding them. They are like chameleons, ever changing and blending in. They have tremendous luck, but also can suffer from extremes in fortune and mood. To be successful, they need to build a loving foundation. Famous 9's: Albert Schweitzer, Shirley MacLaine, Harrison Ford, Jimmy Carter, Elvis Presley. ";
248 }
249
250 cout << endl<< endl;
251
252 zodSign = zodSign - 2;
253
254 if (zodSign == 1){
255 zodiac = "Aries: Date of Birth: March 21 -April 19, Strength: hopeful, active, energetic, honest, versatile, brave, adventurous, passionate, generous, cheerful, argumentative, curious. Weakness: impulsive, naive, self-willed, belligerent, impatien. Symbol: Ram. Element: Fire. Sign Ruler: Mars. Lucky Color: Red. Lucky Number: 5. Jewelry: Ruby. Best Match: Leo, Sagittarius and Aries. Celebrities: Hans Christian Andersen, Jackie Chan, Mariah Carey, Marlon Brando, Dennis Quaid";
256 }
257 else if (zodSign == 2){
258 zodiac = "Taurus: Date of Birth: April 20 - May 20. Strength: romantic, decisive, logical, diligent, ardent, patient, talented in art, perseverant, benevolent. Weakness: prejudiced, dependent, stubborn. Symbol: Bull. Element: Earth. Sign Ruler: Venus. Lucky Color: Pink. Lucky Number: 6. Jewelry: Emerald, Jade. Best Match: Capricorn, Virgo and Taurus. Celebrities: Karl Marx, William Shakespeare, Leonardo da Vinci, David Beckham, Al Pacino";
259 }
260 else if (zodSign == 3){
261 zodiac = "Gemini: Date of Birth: May 21 - June 21. Strength: multifarious, perspicacious, smart, cheerful, quick-witted, clement, charming. Weakness: fickle, gossipy, amphibian. Symbol: Twins. Element: Air. Sign Ruler: Mercury. Lucky Color: Yellow. Lucky Number: 7. Jewelry: Opal. Best Match: Aquarius, Libra and Gemini. Celebrities: John F. Kennedy, Queen Victoria";
262 }
263 else if (zodSign == 4){
264 zodiac = "Cancer: Date of Birth: June 22 - July 22. Strength: with strong sixth sense, subjective, gentle, swift, imaginative, careful, dedicated, perseverant, kind, caring. Weakness: greedy, possessive, sensitive, prim. Symbol: Crab. Element: Water. Sign Ruler: Moon. Lucky Color: Green. Lucky Number: 2. Jewelry: Pearl. Best Match: Pisces, Scorpio and Cancer. Celebrities: Alexander the Great, Raul Gonzalez";
265 }
266 else if (zodSign == 5){
267 zodiac = "Leo: Date of Birth: July 23 - August 22. Strength: proud, charitable, reflective, loyal and enthusiastic. Weakness: arrogant, vainglorious, indulgent, wasteful, willful, and self-complacent. Symbol: Lion. Element: Fire. Sign Ruler: Sun. Lucky Colors: Red, Gold, Yellow. Lucky Number: 19. Jewelry: Gold. Best Match: Aries, Sagittarius and Leo. Celebrities: Napoleon Bonaparte, Deng Xiaoping, Alexander Dumas, Jennifer Lopez, Whitney Houston, Sarah Brightman";
268 }
269 else if (zodSign == 6){
270 zodiac = "Virgo: Date of Birth: August 23 - September 22. Strength: helping, elegant, perfectionist, modest, practical, clearheaded. Weakness: picky, nosey, tortuous, confining. Symbol: Virgin maiden. Element: Earth. Sign Ruler: Mercury. Lucky Color: Gray. Lucky Number: 7. Jewelry: Sapphire, Amber. Best Match: Sagittarius, Taurus and Gemini. Celebrities: Warren Buffett, Kobe Bryant, Michael Jackson, Rebecca De Mornay, Richard Gere";
271 }
272 else if (zodSign == 7){
273 zodiac = "Libra: Date of Birth: September 23 - October 23. Strength: idealistic, equitable, just, strong social skills, aesthetic, charming, artistic, beautiful, kind-hearted. Weakness: hesitant, narcissistic, lazy, perfunctory, freewheeling. Symbol: Scales. Element: Air. Sign Ruler: Venus. Lucky Color: Brown. Lucky Number: 3. Jewelry: Coral, Amber. Best Match: Aquarius, Gemini and Libra. Celebrities: Oscar Wilde, Hillary Duff, Italo Calvino, Evander Hoilrield";
274 }
275 else if (zodSign == 8){
276 zodiac = "Scorpio: Date of Birth: October 24 - November 22. Strength: mysterious, rational, intelligent, independent, intuitive, dedicated, insightful, charming, sensible. Weakness: suspicious, fanatical, complicated, possessive, arrogant, self-willed, extreme. Symbol: Scorpion. Element: Water. Sign Ruler: Pluto, Mars. Lucky Colors: Purple, Black. Lucky Number: 4. Jewelry: Jasper, Black Crystal. Best Match: Cancer, Capricorn and Pisces. Celebrities: Charles de Gaulle, Bill Gates, Marie Curie, Hillary Clinton, Julia Roberts, Pablo Picasso";
277 }
278 else if (zodSign == 9){
279 zodiac = "Sagittarius: Date of Birth: November 23 - December 21. Strength: insightful, superior, rational, brave, beautiful, lively, lovely, optimistic. Weakness: forgetful, careless, rash. Symbol: Archer. Element: Fire. Sign Ruler: Jupiter. Lucky Color: Light Blue. Lucky Number: 6. Jewelry: Amethyst. Best Match: Virgo, Leo and Aries. Celebrities: Mark Twain, Beethoven, Taylor Swift, Britney Spears";
280 }
281 else if (zodSign == 10){
282 zodiac = "Capricorn: Date of Birth: December 22 - January 19. Strength: excellent, intelligent, practical, reliable, perseverant, generous, optimistic, cute, persistent. Weakness: stubborn, lonely, and suspicious. Symbol: Goat. Element: Earth. Sign Ruler: Saturn. Lucky Colors: Brown, Black, Dark Green. Lucky Number: 4. Jewelry: Black Jade. Best Match: Virgo, Taurus and Pisces. Celebrities: Mao Zedong, Issac Newton, Martin Luther King, Nicholas Cage";
283 }
284 else if (zodSign == 11){
285 zodiac = "Aquarius: Date of Birth: January 20 - February 18. Strength: original, tolerant, ideal, calm, friendly, charitable, independent, smart, practical. Weakness: changeful, disobedient, liberalistic, hasty, rebel. Symbol: Water carrier. Element: Air. Sign Ruler: Uranus. Lucky Color: Bronze. Lucky Number: 22. Jewelry: Black Pearl. Best Match: Gemini, Libra and Aquarius. Celebrities: Francis Bacon, Thomas Edison, Agyness Deyn, Paris Hilton";
286 }
287 else if(zodSign == 12){
288 zodiac = "Pisces: Date of Birth: February 19 - March 20. Strength: conscious, aesthetic, platonic, dedicated, kind, with good temper. Weakness: recessive, sentimental, indecisive, unrealistic. Symbol: Fish. Element: Water. Sign Ruler: Neptune. Lucky Color: White. Lucky Number: 11. Jewelry: Ivory Stone. Best Match: Scorpio, Cancer and Capricorn. Celebrities: George Washington, Zhou Enlai, Albert Einstein, Justin Bieber";
289
290 }
291
292
293}
294
295
296
297
298
299
300
301
302
303
304
305
306
307def.h
308
309
310
311
312
313
314
315
316
317
318#include <string>
319
320class def
321{
322 public:
323 void getData();
324 void math();
325 void Zodif();
326 void printResults();
327 void getStats();
328
329
330
331 std::string name, zodiac, chinese, personality;
332 int Byear, Bmonth, Bday, sum, bnum, chyr, currentTime, currentDay, Ayear, Aday, Amonth, day, AAday, AAAday, zodSign;
333 double phy, emo, intel, intu, spi, awa, aes;
334 const double PI = 3.14159265358979323846;
335
336
337};
338
339
340
341
342
343
344
345
346
347
348
349
350
351sqlutil.cpp
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368#include <cstdlib>
369#include <string>
370#include <cstring>
371#include <sstream>
372#include <iostream>
373#include <sqlite3.h>
374#include "SQLutil.h"
375#include "def.h"
376
377using namespace std;
378
379sqlite3 *db;
380int dbopen = sqlite3_open("personality.sqlite", &db);
381
382sqlutilc::sqlutilc(){
383 sqlite3_open("personality.sqlite", &db);
384 szErrMsg = 0;
385 const char *createdbstatement = "CREATE TABLE IF NOT EXISTS personality(daysalive REAL, personality VARCHAR(1500), sign VARCHAR(250), NewYearAnimal VARCHAR(300), intellectual REAL, emotional REAL, physical REAL, intuition REAL, spiritual REAL, awareness REAL, aesthetic REAL)";
386 int ct = sqlite3_exec(db,createdbstatement,callback,0,&szErrMsg);
387 if (ct != SQLITE_OK) {
388 cerr << "SQL Error: Could not create table. Code: " << szErrMsg << endl;
389 sqlite3_free(szErrMsg);
390 exit(1);
391 }
392}
393
394int sqlutilc::callback(void *NotUsed, int argc, char **argv, char **szColName) {
395 for (int i = 0; i < argc; i++)
396 cout << szColName[i] << " = " << argv[i] << endl;
397 cout << endl;
398 return 0;
399}
400
401void sqlutilc::insertData(double day,string personality,string zodiac,string chinese,double intel,double emo,double phy, double intu, double spi, double awa, double aes) {
402 stringstream oss;
403
404 oss << "INSERT INTO personality(daysalive,personality,sign,NewYearAnimal,intellectual,emotional,"
405 "physical, intuition, spiritual, awareness, aesthetic) VALUES (\"" << to_string(day) << "\",\"" << personality << "\",\"" << zodiac << "\",\"" << chinese << "\",\"" << to_string(intel) << "\",\"" << to_string(emo) << "\",\"" << to_string(phy) <<"\",\"" << to_string(intu) << "\",\"" << to_string(spi) << "\",\"" << to_string(awa) << "\",\"" << to_string(aes) << "\")";
406
407 string data = oss.str();
408 char *datatowrite = new char[data.length() + 1];
409 strcpy(datatowrite, data.c_str());
410 int insd = sqlite3_exec(db,datatowrite,callback,0,&szErrMsg);
411
412 if (insd != SQLITE_OK) {
413 cerr << "SQL Error: Could not insert data. Code: " << szErrMsg << endl;
414 sqlite3_free(szErrMsg);
415 exit(1);
416 }
417}
418
419void sqlutilc::closeDB() {
420 if (db)
421 sqlite3_close(db);
422}
423
424void sqlutilc::executeSQL(char *statement) {
425 int exs = sqlite3_exec(db,statement,callback,0,&szErrMsg);
426 if (exs != SQLITE_OK) {
427 cerr << "SQL Error: Could not execute statement. Code: " << szErrMsg << endl;
428 sqlite3_free(szErrMsg);
429 exit(1);
430 }
431}
432
433
434
435
436
437
438
439
440SQLUtil.h
441
442
443
444
445
446
447
448
449
450
451
452#include <sqlite3.h>
453#include <cstdlib>
454
455using namespace std;
456
457class sqlutilc {
458 public:
459 sqlutilc();
460 static int callback(void*,int,char**,char**);
461 void insertData(double,string,string,string,double,double,double,double,double,double,double);
462 void closeDB();
463 void executeSQL(char*);
464
465 private:
466 char *szErrMsg;
467};