|
How do I add a window to this program?
#include "stdafx.h"
#define DEBUG
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();
}
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;
}
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)
{
case '8': {
notepad();
break;
}
case '0': {
cout << "- Please close Notepad to exit - ";
return 0;
}
case '9': {
question();
break;
}
case '7': {
reload();
break;
}
case '6': {
do {
time();
cout << "Press Enter to exit";
Sleep(750);
} while (_getch() != '\n');
break;
}
default: {
cout << "Nope" << endl;
break;
}
}
return 1;
}
void CEditor::question(void) {
myFile.open("AI.txt", ios_base::app);
myFile << "\n----- new entry -----\n";
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;
system("CLS");
_time64(&long_time);
err = _localtime64_s(&newtime, &long_time);
if (err)
{
printf("Invalid argument to _localtime64_s.");
exit(1);
}
if (newtime.tm_hour > 12) strcpy_s(am_pm, sizeof(am_pm), "PM");
if (newtime.tm_hour > 12) newtime.tm_hour -= 12; if (newtime.tm_hour == 0) newtime.tm_hour = 12;
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");
return 0;
}
|
|
|
|
|
Use one of the templates that comes with Visual Studio, or samples that come with the Windows SDK. And please use the correct forum, this one is for C++/CLI.
|
|
|
|
|
Hi every one.
I want to create all rhythmic figures in music. I have an array for durations:
public static double[] duration_fltarray = new double[7];
duration_fltarray[0] = 1;
duration_fltarray[1] = 0.5;
duration_fltarray[2] = 0.25;
duration_fltarray[3] = 0.125;
duration_fltarray[4] = 0.625;
duration_fltarray[5] = 0.3125;
duration_fltarray[6] = 0.15625;
This array shows music times: 1 - 1/2 - 1/4 - 1/8 and so on.
I think it should be written by recursive function, because I couldn't do it by while and for loop.
Now, I need all sorted figures that sum of them are equal 1. For example:
1
1/2 - 1/2
1/2 - 1/4 - 1/4
1/4 - 1/2 - 1/4
1/4 - 1/4 - 1/2
1/4 - 1/4 - 1/4 - 1/4
1/8 - 1/2 - 1/4 - 1/8
1/8 - 1/2 - 1/8 - 1/4
1/8 - 1/2 - 1/8 - 1/8 - 1/8
...
Of course, number of figures will be too many more if we add 1/16 and 1/32 and ... .
I can print them in a web page(response.write) or in a c console; it's not important. But the algorithm should be as simple as possible.
Thank you all.
|
|
|
|
|
|
HackerMan has a message in form of digits but he wants to decode the message so that if enemies gets hold of the message they will not be completely able to decode the message.
Since the message consists only of number, So decoding involves reversing the number. The first digit becomes last and vice versa. For example, if there is 1245 in the code, it becomes 5421 now.
Note : All the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21).
HackerMan is further thinking of complicating the process and he needs your help. Your task is to add the numbers after reversing and output the result after reversing the sum.
Input
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.
Output
For each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers. Omit any leading zeros in the output.
Constraints
The value of N will be less than 10000.
The value of digits will be less than 5000.
|
|
|
|
|
Sorry, but we do not do your homework for you. It is given to you in order to assess your progress on the study course, not to test your ability to copy other people's work.
|
|
|
|
|
Hi All,
Im sure this is easy. I'm forgotten to cpp. I need to write cpp wrapper over a dot net c# web service proxy class. I thought I would start with this basic tutorial...LOL already stuck.
Overview:
I have a Dotnet(c# managed) dll just adding some text to your input string:
public class CSharpClass
{
public static byte[] Hello(byte[] name)
{
string s = ", hello from .NET!";
byte[] helloPart = Encoding.ASCII.GetBytes(s);
byte[] whole =
new byte[name.Length + helloPart.Length];
int i = 0;
foreach (byte b in name)
{
whole[i++] = b;
}
foreach (byte b in helloPart)
{
whole[i++] = b;
}
return whole;
}
}
This get consummed by the CPP dll:
using namespace CSharpAssembly;
__declspec(dllexport) char* __stdcall Hello(char* name)
{
int i = 0;
while (*name != '\0')
{
i++;
name++;
}
array<unsigned char>^ nameManArr = gcnew array<unsigned char>(i);
name -= i;
i = 0;
while (*name != '\0')
{
nameManArr[i] = *name;
name++;
i++;
}
array<unsigned char>^ char8ManArr = CSharpClass::Hello(nameManArr);
char* char8UnmanArr = new char[char8ManArr->Length + 1];
for (int i = 0; i < char8ManArr->Length; i++)
{
char8UnmanArr[i] = char8ManArr[i];
}
char8UnmanArr[char8ManArr->Length] = '\0';
return char8UnmanArr;
}
I have a debug entry test command line app (C#) consuming the C++ dll.
class DebugEntry
{
[DllImport("CppStdcallInerfaceWrapper2.dll",
CharSet = CharSet.Ansi, CallingConvention =
CallingConvention.StdCall)]
public static extern string Hello(string name);
static void Main(string[] args)
{
string sd = Hello("MyName");
System.Console.WriteLine();
System.Console.ReadLine();
}
}
When I run the command line app I can debug through the cpp dll into the C# dll but when I return from the cpp dll I get error on returning to the debug commanline app.
I get error:
An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I'm sure this is something simple?
|
|
|
|
|
What do you mean by returning? You mean after you invoke the static method Hello.
|
|
|
|
|
hi,
i am new and trying to create a dll to use for my .net project
i created a clr dll (class library) project by following the instruction from https://code.google.com/p/tesseractdotnet/wiki/TesseractEngineWrapper
but i keep getting errors from
control.cpp, output.cpp, tessedit.cpp and tesseractemginewrapper.cpp
the error are all the same stating
error C1010: unexpected end of file while looking for precompiled header. did you forget to add '#StdAfx.h' to your source?
as i am completely new i tried with/without the StdAfx.h and StdAfx.cpp which was there when i first created the project.
could anyone help me please?
|
|
|
|
|
The message is telling you exactly what is wrong. Your project is set to use precompiled headers, but you forgot to include StdAfx.h in your source code. Each source file (.cpp file) should include the following line at the top:
#include "StdAfx.h"
|
|
|
|
|
How to sound recorder c++
|
|
|
|
|
|
Hoping somebody can help me with this. I looked for this issue coming up before, but I wasn't able to find anything. May be just my search skills...
Here's the question:
I have a class that generates events, using a custom event args class. That event args class contains a pointer to a large array. Something like this:
public ref struct MyEventArgs : EventArgs {
array<UInt16>^ imageData;
...
}
When this event gets activated, does the event args structure get cloned for each object instance that subscribes to the event, or is there a single instance of the event object with each event handler getting a managed pointer to the same object?
What I'm really getting to is whether the large array gets cloned for each event handler. I'm guessing no.
Many thanks in advance for any pointers (no pun intended...)
|
|
|
|
|
I just tried this out and each event handler received a reference to the same (one and only) MyEventArgs and thus the same array.
I changed some array values in the first event handler and subsequent handlers all saw the modified values in their arrays.
John
|
|
|
|
|
|
|
|
|
Sorry, but I couldn't understand what you want?
Could you explain more clearly?
|
|
|
|
|
Hey Guys,
I read this article regarding " Count from 1 to 1000 without using loops "
=============================================================================
#include <stdio.h>
#include <stdlib.h>
void main(int j) {
printf("%d\n", j);
(&main + (&exit - &main)*(j/1000))(j+1);
}
The only other method to count 1 to 1000 is using recursion. According to C language, j has ‘1’as its value at the beginning. When 1 <= j < 1000, &main + (&exit - &main)*(j/1000) always evaluated to &main, which is the memory address of main. (&main)(j+1) is the next iteration we want to get, which would print ‘2’ on the screen, etc. The stop condition of this recursion is that When j hits 1000, &main + (&exit - &main)*(j/1000) evaluates to &exit, which will elegantly exit this process, and has the error code 1001 returned to the operating system.
=============================================================================
I tried to run this code and its perfectly working, but I am not getting how its works. How it calculates the end condition and all.
Please help me out.
Regards,
Amrit
|
|
|
|
|
The line
(&main + (&exit - &main)*(j/1000))(j+1);
is evaluated each time thus:
&exit - &main is the offset from the start of main to the start of exit
j/1000 will evaluate to zero for all vaules of j less than 1000
Multiplying those two values together gives zero if j is less than 1000.
Add that to &main (the address of main ) and you get the same address, so main gets called with the parameter value j+1 .
This continues until the value of j reaches 1000 at which time:
j/1000 results in the value 1
That is multiplied by the offset of exit which returns that offset.
Add that value to main and the next call will go to exit rather than main .
|
|
|
|
|
Thanks Rechard for this clear explanation.
|
|
|
|
|
Very interesting!
I've never seen this code.
If I wanna plus all numbers between 1 to 1000 with out loops, how can I do it like above method?
Thank you for you advice!
|
|
|
|
|
Use a static variable and just add the value of j to it each time.
|
|
|
|
|
Thank you! 
|
|
|
|