Click here to Skip to main content
14,546,974 members

Managed C++/CLI

 
AnswerRe: How to save "☺" in a file. C/C++ (Windows Functions) Pin
Frankie-C22-Feb-15 3:24
MemberFrankie-C22-Feb-15 3:24 
QuestionDisplay an image on the button. this image is not from resource but it is a image form a normal file Pin
Member 1118237929-Oct-14 2:34
MemberMember 1118237929-Oct-14 2:34 
AnswerRe: Display an image on the button. this image is not from resource but it is a image form a normal file Pin
Richard MacCutchan29-Oct-14 4:01
mveRichard MacCutchan29-Oct-14 4:01 
QuestionI need some help with c++ Pin
Member 1111856129-Sep-14 8:44
MemberMember 1111856129-Sep-14 8:44 
How do I add a window to this program? Smile | :)

#include "stdafx.h"

#define DEBUG

// Answer class
class CAnswers {
public:
	vector<string> answer;
	CAnswers(void);
	CAnswers(string ans);
	~CAnswers(void);
	int size(void);
} Answers;
CAnswers::CAnswers(void) {
}
CAnswers::CAnswers(string ans) {
	stringstream ss(ans);
	string temp_answer;
	while (getline(ss, temp_answer, ','))
		answer.push_back(temp_answer);
}
CAnswers::~CAnswers(void){
}
int CAnswers::size(void) {
	return answer.size();
}

// Question class
class CQuestion {
	string _question;

public:
	CAnswers* answers;
	CQuestion(void);
	CQuestion(string q_a);
	~CQuestion(void);
	string question(void);
} Question;
CQuestion::CQuestion(void) {
}
CQuestion::CQuestion(string q_a) {
	string ans;

	stringstream ss(q_a);
	getline(ss, _question, ':');
	ss >> ans;
	answers = new CAnswers(ans);
}
string CQuestion::question(void) {
	return _question;
}
CQuestion::~CQuestion(void){
	delete answers;
}

//Editor class
class CEditor {
	vector<CQuestion> questions;
	ofstream myFile;
	int age, address;
	char selection, character[1];
	string name, response;
	HANDLE np;
	unsigned notepadID;

public:
	CQuestion* q;
	CEditor(void);
	~CEditor(void);
	int menu(void);
	void question(void);
	void reload(void);
	int time(void);
	static unsigned int __stdcall notepadThread(void* arg);
	void notepad(void);
} Editor;
CEditor::~CEditor(void){
	delete q;
}
CEditor::CEditor(void) {
	np = 0;
}
unsigned int __stdcall CEditor::notepadThread(void* arg) {
	system("notepad.exe AI.txt");
	_endthreadex(0);
	return 0;
}
void CEditor::notepad(void) {
	_beginthreadex(NULL, 0, &CEditor::notepadThread, np, 0, ¬epadID);
}
int CEditor::menu(void) {
	system("CLS");
	cout << "Menu:\n9 = Basic Information.\n8 = DATALOG\n7 = Reload \n6 = Time\n0 = Leave\n";
	cin >> selection;

	switch (selection)
	{
		// Open text in notepad
	case '8': {
		notepad();
		break;
	}
		// Exit program
	case '0': {
		cout << "- Please close Notepad to exit - ";
		return 0;
	}
		// Ask questions and place answers into AI.txt
	case '9': {
		question();
		break;
	}
		// Simulate reloading program,
	case '7': {
		reload();
		break;
	}
		// Clock
	case '6': {
		do {
			time();
			cout << "Press Enter to exit";
			Sleep(750);
		} while (_getch() != '\n');
		break;
	}
		// Invalid response
	default: {
		cout << "Nope" << endl;
		break;
	}
	}
	return 1;
}
void CEditor::question(void) {
	// Open file and move to end of file.
	myFile.open("AI.txt", ios_base::app);
	myFile << "\n----- new entry -----\n";
	// Clear console and ask questions.
	system("CLS");
	cout << "AI: What is your name?" << endl;
	cin >> name;
	system("CLS");
	myFile << "Datalog" << "\nName: " << name << endl;

	cout << "AI: How are you feeling?" << endl << name << ": ";
	cin >> response;
	system("CLS");
	if (response == character) {
		cout << "Invalid answer";
	}
	myFile << name << " is feeling " << response << endl;
	cout << "AI: What is your age " << name << "?" << endl << name << ": ";
	cin >> age;
	system("CLS");
	myFile << name << "'s age is " << age;
	myFile.close();
	if (!myFile)
	{
		cout << "Error";
	}
}
void CEditor::reload(void) {
	system("CLS");
	cout << "Reloading";
	Sleep(1000);
	cout << ".";
	Sleep(1000);
	cout << ".";
	Sleep(1000);
	cout << ".";
}
int CEditor::time(void) {
	struct tm newtime;
	char am_pm[] = "AM";
	__time64_t long_time;
	char timebuf[26];
	errno_t err;

	// Clear the screen
	system("CLS");
	// Get time as 64-bit integer.
	_time64(&long_time);
	// Convert to local time.
	err = _localtime64_s(&newtime, &long_time);
	if (err)
	{
		printf("Invalid argument to _localtime64_s.");
		exit(1);
	}
	if (newtime.tm_hour > 12)        // Set up extension.
		strcpy_s(am_pm, sizeof(am_pm), "PM");
	if (newtime.tm_hour > 12)        // Convert from 24-hour
		newtime.tm_hour -= 12;    // to 12-hour clock.
	if (newtime.tm_hour == 0)        // Set hour to 12 if midnight.
		newtime.tm_hour = 12;

	// Convert to an ASCII representation.
	err = asctime_s(timebuf, 26, &newtime);
	if (err)
	{
		printf("Invalid argument to asctime_s.");
		exit(1);
	}
	printf("%.19s %s\n", timebuf, am_pm);
	return 1;
}

int _tmain(int argc, _TCHAR* argv[])
{
	CEditor editor;
	editor.q = new CQuestion("How are you?:Good,Bad");
	cout << editor.q->question() << endl;
	for (int i = 0; i<editor.q->answers->size(); ++i) {
		cout << editor.q->answers->answer[i] << endl;
	}
	system("pause");
	//while(editor.menu());
	return 0;
}

AnswerRe: I need some help with c++ Pin
Richard MacCutchan29-Sep-14 21:33
mveRichard MacCutchan29-Sep-14 21:33 
QuestionCoding music rhythms Pin
Navid Abyazi24-Sep-14 5:28
professionalNavid Abyazi24-Sep-14 5:28 
AnswerRe: Coding music rhythms Pin
Richard MacCutchan24-Sep-14 5:35
mveRichard MacCutchan24-Sep-14 5:35 
QuestionReverse No program Pin
Member 105011307-Sep-14 20:09
MemberMember 105011307-Sep-14 20:09 
AnswerRe: Reverse No program Pin
Richard MacCutchan7-Sep-14 21:23
mveRichard MacCutchan7-Sep-14 21:23 
QuestionSystem.AccessViolationException - Returning from cpp dll Pin
ToolMaker200716-Aug-14 4:25
MemberToolMaker200716-Aug-14 4:25 
AnswerRe: System.AccessViolationException - Returning from cpp dll Pin
Member 1048772028-Aug-14 21:45
MemberMember 1048772028-Aug-14 21:45 
Questionneed help with creating a clr dll Pin
neodeaths13-Aug-14 21:57
Memberneodeaths13-Aug-14 21:57 
AnswerRe: need help with creating a clr dll Pin
Richard MacCutchan13-Aug-14 22:26
mveRichard MacCutchan13-Aug-14 22:26 
QuestionHow to sound recorder c++ Pin
4manes6-Jul-14 22:58
Member4manes6-Jul-14 22:58 
AnswerRe: How to sound recorder c++ Pin
Richard MacCutchan7-Jul-14 2:46
mveRichard MacCutchan7-Jul-14 2:46 
QuestionDumb question about event arguments Pin
Member 1031630012-Jun-14 20:21
MemberMember 1031630012-Jun-14 20:21 
AnswerRe: Dumb question about event arguments Pin
John Schroedl13-Jun-14 8:05
professionalJohn Schroedl13-Jun-14 8:05 
GeneralRe: Dumb question about event arguments Pin
Member 1031630013-Jun-14 8:50
MemberMember 1031630013-Jun-14 8:50 
Ranthow to work with window in c++ Pin
TomTomtz30-May-14 12:02
MemberTomTomtz30-May-14 12:02 
GeneralRe: how to work with window in c++ Pin
Wes Aday30-May-14 12:29
professionalWes Aday30-May-14 12:29 
GeneralRe: how to work with window in c++ Pin
Richard MacCutchan30-May-14 22:08
mveRichard MacCutchan30-May-14 22:08 
GeneralRe: how to work with window in c++ Pin
WuRunZhe19-Jun-14 5:39
MemberWuRunZhe19-Jun-14 5:39 
QuestionCount from 1 to 1000 without using loops Pin
Amrit Agr26-May-14 0:09
MemberAmrit Agr26-May-14 0:09 
AnswerRe: Count from 1 to 1000 without using loops Pin
Richard MacCutchan26-May-14 0:42
mveRichard MacCutchan26-May-14 0:42 
GeneralRe: Count from 1 to 1000 without using loops Pin
Amrit Agr26-May-14 21:09
MemberAmrit Agr26-May-14 21:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.