|
mostafaghanei wrote: this code is a part of keecak function
Ahh, Keecak eh? Yes, that's very well known. I am sure someone can tell you what it does.
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|
THE QUESTION IS AS FOLLOWS:
Create a template class called Array that implements an array and works with any type (int, double, etc.). The constructor should take a size for the array and use new to allocate memory (don't forget to delete in the destructor). Overload operator[] to access the elements of the array. If an attempt is made to access an element outside the array bounds (either above OR below), throw an exception. In the main program, first create an Array<int> object, add a few values, and demonstrate that operator[] throws an exception if an attempt is made to access an out-of-bounds elements. Catch the exception and print an appropriate message. Then do the same thing with an Array<std::string>.
Hint: you will need both of these overloads:
T& operator[](int i)
const T& operator[](int i) const
I DID THE PROGRAM IN MAIN AS FOLLOWS AND IT DOES WELL IN THE MAIN BUT ITS GIVING ME HARD TIME DIVIDING IT INTO DIFFERENT FILES.
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
template <typename T>
class Array
{
int size; T*array;
public:
Array(int s)
{
size=s;
array=new T [size];
}
~Array()
{
delete [] array;
}
const T &operator[](int i) const
{
if(i < 0)
throw exception("Index out of bounds LOWER");
else if(i>=size)
throw exception("Index out of Bounds OVER");
else
return array[i];
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Array <int> num(12);
try
{
int i=num[-1];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
Array <string> num1(12);
try
{
string j=num1[14];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
cin.get();
cin.get();
return 0;
}
THEN I DIVIDED THE PROGRAM INTO DIFFERENT FILES AS FOLLOWS:
IN ARRAY.H
#pragma once
template <typename T>
class Array
{
public:
Array(int s);
~Array();
const T &operator[](int i)const;
private:
int size; T*array;
};
IN ARRAY.CPP
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
template <typename T>
Array<T>::Array(int s)
{
size=s;
array=new T [size];
}
template <typename T>
Array<T>::~Array()
{
delete [] array;
}
template <typename T>
const T & Array<T>::operator[](int i) const
{
if(i < 0)
throw exception("Index out of bounds LOWER");
else if(i>=size)
throw exception("Index out of Bounds OVER");
else
return array[i];
}
IN MAIN
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
int _tmain(int argc, _TCHAR* argv[])
{
Array <int> num(12);
try
{
int i=num[-1];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
Array <string> num1(12);
try
{
string j=num1[14];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
cin.get();
cin.get();
return 0;
}
PLEASE REPLY SOON.
|
|
|
|
|
|
You do not need ARRAY.CPP, all that code should be in the header file, following the class definition.
|
|
|
|
|
@Richardd MacCutchann
But the checklist is as follows:
hecklist
1. Did NOT create a folder for the solution
2. Project/solution named correctly
3. Correct comments at top
4. Consistent indentation
5. Good variable names
6. Overall neat organization
7. Comments in code explain what's being done
8. Correct division of code into .h and .cpp files
9. Use of #pragma once in .h files (or, #ifndef)
10. #include "stdafx.h" in cpp files (or, suppress pch)
11. Test for below as well as above out-of-range
|
|
|
|
|
Then you need to follow the instructions and do your own work.
|
|
|
|
|
@Richard-MacCutchann
I actually did and have posted the main program and my attempt to divide it into .cpp and .h files i am almost there and i just need help to figure out the minor mistakes i have made . if you look at my main post you will see all the program please have a look and let me know if you can help me or not thanks.
|
|
|
|
|
I already gave you a suggestion. If you want more help then you need to provide a more detailed explanation of your problem.
|
|
|
|
|
if you look at the main question i have my main program that runs and gives me desired output but when i try to make a seperate .cpp and .h files for the program (that i also have attached in the main question) gives me some error so i want to request you to have a look at that and let me know what i should do to make the program work with a seperate .cpp and .h file for the main program that i have attached in the question
|
|
|
|
|
I have looked, and I have given you a suggestion; it is up to you to implement it. You then need to build and test until it runs successfully.
You also need to provide specific details of the errors you receive if you want further help.
|
|
|
|
|
THE QUESTION IS AS FOLLOWS:
Create a template class called Array that implements an array and works with any type (int, double, etc.). The constructor should take a size for the array and use new to allocate memory (don't forget to delete in the destructor). Overload operator[] to access the elements of the array. If an attempt is made to access an element outside the array bounds (either above OR below), throw an exception. In the main program, first create an Array<int> object, add a few values, and demonstrate that operator[] throws an exception if an attempt is made to access an out-of-bounds elements. Catch the exception and print an appropriate message. Then do the same thing with an Array<std::string>.
Hint: you will need both of these overloads:
T& operator[](int i)
const T& operator[](int i) const
I DID THE PROGRAM IN MAIN AS FOLLOWS AND IT DOES WELL IN THE MAIN BUT ITS GIVING ME HARD TIME DIVIDING IT INTO DIFFERENT FILES.
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
template <typename T>
class Array
{
int size; T*array;
public:
Array(int s)
{
size=s;
array=new T [size];
}
~Array()
{
delete [] array;
}
const T &operator[](int i) const
{
if(i < 0)
throw exception("Index out of bounds LOWER");
else if(i>=size)
throw exception("Index out of Bounds OVER");
else
return array[i];
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Array <int> num(12);
try
{
int i=num[-1];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
Array <string> num1(12);
try
{
string j=num1[14];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
cin.get();
cin.get();
return 0;
}
THEN I DIVIDED THE PROGRAM INTO DIFFERENT FILES AS FOLLOWS:
IN ARRAY.H
#pragma once
template <typename T>
class Array
{
public:
Array(int s);
~Array();
const T &operator[](int i)const;
private:
int size; T*array;
};
IN ARRAY.CPP
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
template <typename T>
Array<T>::Array(int s)
{
size=s;
array=new T [size];
}
template <typename T>
Array<T>::~Array()
{
delete [] array;
}
template <typename T>
const T & Array<T>::operator[](int i) const
{
if(i < 0)
throw exception("Index out of bounds LOWER");
else if(i>=size)
throw exception("Index out of Bounds OVER");
else
return array[i];
}
IN MAIN:::
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
int _tmain(int argc, _TCHAR* argv[])
{
Array <int> num(12);
try
{
int i=num[-1];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
Array <string> num1(12);
try
{
string j=num1[14];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
cin.get();
cin.get();
return 0;
}
|
|
|
|
|
Hi, I'm trying to build my C++/CLI project with /W4 today and there's a warning I can't seem to avoid and hope someone here can help.
My project has a reference to Microsoft.mshtml for the web browser interfaces. At the first usage in code, I get a slew of warning similar to this:
1>htmlView.cpp(244): warning C4564: method 'open' of interface 'mshtml::DispHTMLDocument' defines unsupported default parameter 'url'
1> This diagnostic occurred while importing type 'mshtml::DispHTMLDocument ' from assembly 'Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
1> This diagnostic occurred while importing type 'mshtml::HTMLDocumentClass ' from assembly 'Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
I understand why it's warning (there are optional parameters in the managed interface but the generated C++ interface doesn't have the default values). That's fine.. I'd like to suppress the warning since I can't really do anything about the generated code.
I tried the following in various of places in the code including wrapping the whole file with it. Alas, it doesn't prevent the warning.
#pragma warning( push )
#pragma warning( suppress : 4564 ) // /W4 will warn about optional parameters in mshtml interface
. . . CLI Code . . .
#pragma warning(pop)
If possible, I'd prefer to suppress it in the source instead of a compile-time switch so I thought I'd ask here... any suggestions?
John
|
|
|
|
|
I gave up and am disabling this warning for the affected file in the vcxproj. Oh well, would have been nice to suppress in source.
John
|
|
|
|
|
Good Afternoon!
I'm trying to use the functions in the DLL created in C #, I need to read the functions in borland c + + builder, anyone have any suggestions?
|
|
|
|
|
Compile the C# object with the "Make COM Visible" checkbox checked, and then see this link:
COM Callable Wrapper[^]
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hello ,
I have a problem.
I have a HTML page like this:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="/repertoire1/css/defaulthtml/reset.css" type="text/css" />
<link xmlns="" rel="stylesheet" href="/repertoire1/css/defaulthtml/default_theme.css"
type="text/css"></link><script type="text/javascript">
<title> Test HTML</title>
</head>
<body>
<div id="alert"></div>
<div class="data">
<div class="line-item">word1 word2 word3 word 4 word5 <br /> word7 word8 word9
</div>
</div>
<div class="footer"><a href="#" id="2" class="button enabled">Arreter</a><a href="#" id="3" class="button enabled">Annuler</a></div>
<script type="text/javascript" src="/repertoire1/test/.js"></script>
<script type="text/javascript">
$(document).ready(function () {
init();
});
</script></body>
</html>
I record this page in xml or txt file. I walk through the xml file and I have only recovered one by one word while cleaning the html tag like this one:
word1
word2
word3 ...
The question is : how to retrieve the words one by one, please
Thank you in advance.
|
|
|
|
|
This is the Managed C++ forum; please post your question in the proper place.
|
|
|
|
|
I think I'm good endroit.parce I have to do all this in c + + / cli.
I get the source code of the site with c + + and I have records in a xml file. I route the file and now I have to recover word and it will be with c + + / cli.
|
|
|
|
|
|
|
I want to use a mm_timer for my application by 60Hz or less . This is my testing code.
- In "testmmtimerDlg.h" header file:
#include "mmsystem.h"
#pragma once
#pragma comment(lib, "winmm.lib")
public:
double m_dcount;
static void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
void MMTimerHandler(UINT nIDEvent);
void StopTimer();
MMRESULT m_Timer;
DWORD resolution;</pre>
- In "testmmtimerDlg.cpp" file:
<pre>void CtestmmtimerDlg::OnBnClickedTest()
{
m_dcount = 0;
TIMECAPS tc;
timeGetDevCaps(&tc, sizeof(TIMECAPS));
resolution = min(max(tc.wPeriodMin, 0), tc.wPeriodMax);
timeBeginPeriod(resolution);
m_Timer = timeSetEvent(10,resolution,TimeProc,(DWORD)this,TIME_PERIODIC);
}
void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
CtestmmtimerDlg* obj = (CtestmmtimerDlg*) dwUser;
obj->MMTimerHandler(wTimerID);
}
void CtestmmtimerDlg::StopTimer()
{
timeKillEvent(m_Timer);
timeEndPeriod (resolution);
}
==>> But when I try to debug, I have 2 problem:
- First, "
testmmtimerDlg.obj : error LNK2019: unresolved external symbol "public: static void __stdcall CtestmmtimerDlg::TimeProc(unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)" (?TimeProc@CtestmmtimerDlg@@SGXIIKKK@Z) referenced in function "public: void __thiscall CtestmmtimerDlg::OnBnClickedTest(void)" (?OnBnClickedTest@CtestmmtimerDlg@@QAEXXZ)
1>C:\Users\HungReo\Documents\Visual Studio 2010\Projects\testmmtimer\Debug\testmmtimer.exe : fatal error LNK1120: 1 unresolved externals
"
- Second, in header file, I try to change:
void (CALLBACK *TimeProc)(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
==>>>> OxC0000005: Access Violoation
- May someone help me to solve these problem???
modified 31-Mar-14 0:54am.
|
|
|
|
|
void (CALLBACK *TimeProc)(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
You are declaring TimeProc as a pointer to a function which is totally incorrect.
It should be like:
void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
void CALLBACK CtestmmtimerDlg::TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
}
|
|
|
|
|
Thank you very much for your help! But when I try to follow your code, the error will be:
error C3867: 'CtestmmtimerDlg::TimeProc': function call missing argument list; use '&CtestmmtimerDlg::TimeProc' to create a pointer to member
|
|
|
|
|
I finished to run it ^^. Just move the CALLBACK function before click button and don't need to declare CALLBACK in header file. Thank you so much for your help ^^
|
|
|
|
|