November 27, 2014, 3:26 am
Hello, im trying to port a code from vc6 to vs2013 and im having this error
Code:
Error 11 error C2440: 'initializing' : cannot convert from 'char *' to 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<char>>>'
on this line
Code:
vector<char>::iterator BufIt = (char*)lpBuffer;
what i do with this is to stack fragments of data of type char* coming from a socket in buffer to a vector that acts as buffer, I do this since I transfer big chunks of data and the data gets fragmented by the nature of the sockets, I stack the data once its complete I retrieve the final result from the vector.
this code worked flawlessly for long time but now Im trying to port and compiler throws this error, whats the new way to assign a char array pointer to a iterator so i can stack it in the vector.
Thx in advance.
↧
November 27, 2014, 3:30 pm
i have a project where i create a dice game, the user rolls 2 dice and the computer roles 2 dice. the player that wins 3 out of 5 rolls wins the game. I have completed the requirements, but i wanted to create a pass by value function for "void Dice()", I'm not too sure how that works, if someone could please help i would be forever grateful.
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
//creating my variables and their values
int compinput;
int input = 0;
int die1 = 0;
int die2 = 0;
int die3 = 0;
int die4 = 0;
int maxtries = 0;
int compwin = 0;
int playerwin = 0;
int snakeeyes = 2;
/*
Name: Dice()
return value: void
parameters: int d
Purpose: creating a simulated random roll for dice
*/
void Dice()
{
die1 = (rand() % 6 + 1);
die2 = (rand() % 6 + 1);
die3 = (rand() % 6 + 1);
die4 = (rand() % 6 + 1);
}
/*
Name: Game()
return value: void
parameters: none
Purpose: setting the rules for the game
*/
void Game()
{
//Dice();
//displays the player and computer die values and adds one to max tries if it is run
cout << " **COMPUTER** " << endl << " Die 1 = " << die3 << endl << " Die 2 = " << die4 << endl << endl;
cout << " **PLAYER** " << endl << " Die 1 = " << die1 << endl << " Die 2 = " << die2 << endl << endl;
maxtries++;
//if the player rolls double one's, they win
if (die1 + die2 == snakeeyes)
{
cout << endl << "SNAKE EYES, YOU WIN" << endl << endl;
playerwin++;
}
//if the computer rolls double one's, the computer wins
else if (die3 + die4 == snakeeyes)
{
cout << endl << "SNAKE EYES, YOU LOSE" << endl << endl;
compwin++;
}
//if there is a tie, the current round is reset
else if ((die1 + die2) == (die3 + die4))
{
cout << endl << "ITS A TIE, GO AGAIN." << endl << endl;
maxtries--;
}
//if the players dice value is less than that of the computers dice value, the player looses that round
else if ((die1 + die2) < (die3 + die4))
{
cout << endl << "YOU LOST" << endl << endl;
compwin++;
}
//if the computers dice value is less than that of the players dice value, the player wins that round
else if ((die1 + die2) > (die3 + die4))
{
cout << endl << "YOU WIN" << endl << endl;
playerwin++;
}
//displays the current round
cout << " ROUND: " << maxtries << endl;
//displays the computer and player scores
cout << "Computer Score : " << compwin << endl << "Your Score : " << playerwin << endl << endl;
//instructing on how to go to the next round
cout << endl << endl << "Press \"0\" then enter to start the next round: ";
//user input
cin >> input;
cout << endl;
}
/*
Name: Main()
return value: int
parameters: none
Purpose: the starting point of my program
*/
int main()
{
//combines time with a random number to simulate a random number
srand(time(NULL));
//if there have been no attempts made to play, the rules will appear on screen but will not use a try when it is displayed
if (maxtries = 1)
{
cout << "Welcome! You are playing a dice game against the computer." << endl << endl << "There will be 5 rounds. During each round you will roll 2 die and the computer" << endl << "will roll 2 die." << endl << endl << "If you have the highest die total you win the round and get a point. If the" << endl << "computer has the highest die total, then the computer wins that round and gets" << endl << "a point. If you and the computer both get the same number then both the player" << endl << "and the computer will roll again for that round." << endl << endl << "At any time if either you or the computer rolls double ones (snake eyes), that" << endl << "player automatically wins the entire game. If the player and the computer both" << endl << "get snake eyes in the same round, the player wins the game." << endl << endl;
maxtries--;
}
//runs this if there have been under 5 rounds attempted
while (maxtries < 5)
{
Dice();
Game();
}
// if the computer won 3 or more times in 5 rounds, the computer won
if (compwin >= 3)
{
cout << "You LOST against the computer " << endl << " Press \"0\" then enter to play again: ";
cin >> input;
compwin = 0;
playerwin = 0;
main();
}
//if the player won 3 or more times in 5 rounds the player wins
else if (playerwin >= 3)
{
cout << "You WON against the computer " << endl << " Press \"0\" then enter to play again: ";
cin >> input;
compwin = 0;
playerwin = 0;
main();
}
//if maxtries reaches above 5, start over
if (maxtries = 6)
{
compwin = 0;
playerwin = 0;
main();
}
}
↧
↧
November 28, 2014, 2:15 pm
Hi guys, if I do this everything works fine:
Code:
char* strings[]={"Zorro", "Alex", "Celine", "Bill", "Forest", "Dexter"};
qsort(strings, 6, sizeof(char*), cmp_func);
However, I like to allocate my strings like this (filenames example):
Code:
// allocate
char** mem=new char*[n]; // allocate pointers
mem[0]=new char[n*MAX_PATH]; // allocate memory
// set pointers
for(int i=1; i<n; i++){
mem[i]=mem[i-1]+MAX_PATH;
}
// fill in strings
...
// sort causes debug assertion failure _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
qsort(mem, n, sizeof(char*), cstring_cmp);
Please help. Thank you.
Edit: Guys, I fixed it:
Code:
// instead of allocating the memory like this...
mem[0]=new char[n*MAX_PATH];
// ...it's better to do it this way (with a new variable) so the pointer won't get shuffled
char* buffer=new char[n*MAX_PATH];
Thanks
↧
November 28, 2014, 7:04 pm
I am pretty new to this subject. I am learning alright as I have toyed with java along with html, css etc..
I am trying to make a basic app that will loop through an unordered list with repeats and count how many times a specific item repeats. Example would be I select a state from the list box and it will tell me how many times it is listed.
This is the code I have up so far, trying to keep it basic. I am missing something, something related to the counter? I think I have some of the better half up but I am not sure...
Code:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstBox.SelectedIndexChanged
Dim wins As String = lstBox.SelectedIndex
Dim foundwins As Boolean = False
Dim i As Integer = -1
Do Until (i = lstBox.Items.Count - 1)
i += 1
If CStr(lstBox.Items(i)).StartsWith(wins) Then
foundwins = True
End If
Loop
If foundwins = True Then
outBox.Text = CStr(lstBox.Items(i))
End If
End Sub
End Class
↧
November 30, 2014, 8:50 am
↧
↧
November 30, 2014, 11:17 am
Hello
I have a child window above an edit control.
When the position of the control in the parent in the child on top of it is clicked the control gets topmost.
Is there any way to prevent this?
Thanks a lot.
↧
December 1, 2014, 7:44 am
Debug build links fine but release build linking hangs at "code generation"
If I turn off whole optimization, it actually works fine, but I do need whole optimization. Does any one have some idea how to solve this issue?
Thanks a lot,
CR
↧
December 1, 2014, 8:49 am
Hi,
I 've build a C++ dll to communicate with c# (my current language).
Dll initialize fine but members are destructed just after. so i get back "try to read or write in protected memory" that meens an initialisation error i think.
someone could tell me what's wrong ?
thanks
Code:
#pragma once
#include "Readers.h"
#include <iostream>
#include <fstream>
using namespace std;
class Caller
{
protected :
__declspec(dllexport)
bool Connect();
public :
CReaders m_cReaders;
static void WriteToLog(CString mess);
Caller();
~Caller();
private :
};
#include "stdafx.h"
#include "Caller.h"
using namespace std;
bool Caller::Connect()
{
// cette méthod est appelée via un lien externe de la dll
// l'instance n'existe plus
if ( this->m_cReaders.Connect(2))
{
WriteToLog("Connection OK!!!!");
}
return true;
}
Caller::Caller()
{
if (this->m_cReaders.CreateReaderList())
{
WriteToLog("m_cReaders.CreateReaderList()OK!!!!");
}
// Ici la connexion est ok puisque l'instance existe
if ( this->m_cReaders.Connect(2))
{
WriteToLog("Connection OK!!!!");
}
}
Caller::~Caller()
{
//if (this->m_cReaders.Disconnect())
//{
// WriteToLog("Déconnection OK");
//}
}
void Caller::WriteToLog(CString mess)
{
ofstream fichier("c:\\temp\\test.txt", ios::app);
if(fichier) // si l'ouverture a réussi
{
fichier << mess << endl;
fichier.close(); // on ferme le fichier
}
}
// NewDLL.cpp : définit les fonctions d'initialisation pour la DLL.
//
#include "stdafx.h"
#include "NewDLL.h"
#include "Caller.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//
//TODO : si cette DLL est liée dynamiquement aux DLL MFC,
// toute fonction exportée de cette DLL qui appelle
// MFC doit avoir la macro AFX_MANAGE_STATE ajoutée au
// tout début de la fonction.
//
// Par exemple :
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // corps de fonction normal ici
// }
//
// Il est très important que cette macro se trouve dans chaque
// fonction, avant tout appel à MFC. Cela signifie qu'elle
// doit être la première instruction dans la
// fonction, avant toute déclaration de variable objet
// dans la mesure où leurs constructeurs peuvent générer des appels à la DLL
// MFC.
//
// Consultez les notes techniques MFC 33 et 58 pour plus de
// détails.
//
// CNewDLLApp
BEGIN_MESSAGE_MAP(CNewDLLApp, CWinApp)
END_MESSAGE_MAP()
// construction CNewDLLApp
CNewDLLApp::CNewDLLApp()
{
// TODO : ajoutez ici du code de construction,
// Placez toutes les initialisations significatives dans InitInstance
Caller c;
}
// Seul et unique objet CNewDLLApp
CNewDLLApp theApp;
// initialisation de CNewDLLApp
BOOL CNewDLLApp::InitInstance()
{
//CWinApp::InitInstance();
return TRUE;
}
↧
December 2, 2014, 8:00 am
Hi, Folks,
I set up some pre-build event to automatically generated some code, which then will be part of the project. The issue is that the so generated code will be not picked up immediately and I have to build twice. Does anyone know how to solve this issue without writing my own script for compiling?
Thanks,
CR
↧
↧
December 2, 2014, 4:32 pm
![Name: J6ABCs7.jpg
Views: 11
Size: 55.2 KB]()
How to solve this application with stack?
Check HTML tags :(
Please help me ^^~
↧
December 2, 2014, 5:17 pm
I get this error:
run-time check failure #0 - the value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention
when i try to run my code. It has compiled fine on another computer, but it simply will not work on this one and i cannot figure out why. This is the part of code where it is receiving the error. it has to do with the stoi
Code:
#include <string> // for use of string
#include <fstream> //for file handling
#include <iostream> // for file handling
#include <cstdlib>
#include <iomanip> //for the setprecision used further below
using namespace std;
struct MasterData //struct created named 'MasterData' to hold one line from master file
{
string playerId,
firstName,
lastName,
division,
teamName;
int appearances,
atBats,
singles,
doubles,
triples,
homeRuns,
sacFly,
walks,
hitByPitch;
double battingAvg,
OBP,
sluggingPercent;
};
struct MasterUpdate // struct created for the Update of the master file
{
string recordType;
MasterData record;
};
std :: istream &operator>>(istream& in, MasterData& d) //Overloads the input and output
{ //Overloads the ">>" operator
std :: string value;
getline(in, d.playerId, ',');
getline(in, d.firstName, ',');
getline(in, d.lastName, ',');
getline(in, d.division, ',');
getline(in, d.teamName, ',');
getline(in, value, ',');
d.appearances = stoi(value);
getline(in, value, ',');
d.atBats = stoi(value);
getline(in, value, ',');
d.singles = stoi(value);
getline(in, value, ',');
d.doubles = stoi(value);
getline(in, value, ',');
d.triples = stoi(value);
getline(in, value, ',');
d.homeRuns = stoi(value);
getline(in, value, ',');
d.sacFly = stoi(value);
getline(in, value, ',');
d.walks = stoi(value);
getline(in, value, ',');
d.hitByPitch = stoi(value);
getline(in, value, ',');
d.battingAvg = stod(value); // stod converts string to double and then stores it in MasterData
getline(in, value, ',');
d.OBP = stod(value);
getline(in, value, '\n');
d.sluggingPercent = stod(value);
return in;
}
ostream &operator<<(ostream& out, MasterData d)
{
//Overloads the "<<" operator
out << setw(11) << d.playerId << "|";
out << setw(15) << d.firstName << "|";
out << setw(15) << d.lastName << "|";
out << setw(15) << d.division << "|";
out << setw(15) << d.teamName << "|";
out << setw(15) << d.appearances << "|";
out << setw(10) << d.atBats << "|";
out << setw(10) << d.singles << "|";
out << setw(10) << d.doubles << "|";
out << setw(10) << d.triples << "|";
out << setw(10) << d.homeRuns << "|";
out << setw(10) << d.sacFly << "|";
out << setw(10) << d.walks << "|";
out << setw(15) << d.hitByPitch << "|";
out << setprecision(3) << fixed;
out << setw(15) << d.battingAvg << "|";
out << setw(15) << d.OBP << "|";
out << setw(15) << d.sluggingPercent << "|";
out << "\n";
return out;
}
istream &operator>>(istream& in, MasterUpdate& u) //Overload operators for MasterUpdate
{
//Overloads the ">>" operator (opposite of the one above)
getline(in, u.recordType, ',');
in >> u.record;
return in;
}
// Function Prototypes
void swap(MasterData stats[], int x, int y);
void sortByBattingAvg(MasterData stats[], int length);
void sortByDivThenBattingAvg(MasterData stats[], int length);
void sortByTeamThenDiv(MasterData stats[], int length);
void printTop20Batters(ostream& out, MasterData stats[], int length);
void printTop10PlayersbyDivision(ostream& out, MasterData stats[], int length);
void printOffensiveStatsbyTeam(ostream& out, MasterData stats[], int length);
void printNewMaster(ostream& out, MasterData stats[], int length);
void printRecordCSV(ostream& out, MasterData d);
void printHeaders(ostream& out);
void lineA(ostream& out);
void lineB(ostream& out);
int main()
{
ifstream inFile;
inFile.open("Master_Data.csv");
MasterData current;
MasterData stats[500];
int length = 0;
while (!inFile.eof())
{
inFile >> current;
stats[length] = current;
length++;
}
inFile.close();
//Update array for 2014 stats then print out the updated master file
MasterUpdate update;
ifstream inleagueData("2014_League_Stats.csv");
string value;
//Remove Headers
for (int i = 0; i < 17; i++)
getline(inleagueData, value, ',');
getline(inleagueData, value, '\n');
//Make updates
while (!inleagueData.eof())
{
inleagueData >> update;
switch (update.recordType[0])
{
case 'D': //Delete player that did not return to league
for (int i = 0; i < length; i++)
if (update.record.playerId == stats[i].playerId)
{
swap(stats, i, length - 1);
length--;
}
break;
case 'N': //Add new player that is entering the league
stats[length] = update.record;
length++;
break;
case 'R': //Update stats for player returning to league
int position;
for (int i = 0; i < length; i++)
if (update.record.playerId == stats[i].playerId)
position = i;
//Update record based on new stats
stats[position].teamName = update.record.teamName;
stats[position].division = update.record.division;
stats[position].appearances += update.record.appearances;
stats[position].atBats += update.record.atBats;
stats[position].singles += update.record.singles;
stats[position].doubles += update.record.doubles;
stats[position].triples += update.record.triples;
stats[position].homeRuns += update.record.homeRuns;
stats[position].sacFly += update.record.sacFly;
stats[position].walks += update.record.walks;
stats[position].hitByPitch += update.record.hitByPitch;
//Update hits based on new stats
double hits = 0;
hits += stats[position].singles;
hits += stats[position].doubles;
hits += stats[position].triples;
hits += stats[position].homeRuns;
//Update total bases based on the updated hits
double totalBases = 0;
totalBases += stats[position].singles;
totalBases += stats[position].doubles * 2;
totalBases += stats[position].triples * 3;
totalBases += stats[position].homeRuns * 4;
//Update calculated fields for batting average, OBP, and slugging percent
stats[position].OBP = ((hits + stats[position].walks + stats[position].hitByPitch)
/ stats[position].appearances);
stats[position].sluggingPercent = (totalBases / stats[position].atBats);
break;
}
}
//Display the updated master file
ofstream outNewMaster("2014_League_Stats.csv");
printNewMaster(outNewMaster, stats, length);
outNewMaster.close();
//Processing and Output 1 - Top 20 Batters Report
sortByBattingAvg(stats, length);
ofstream top20("Top 20 Batters.txt");
printTop20Batters(top20, stats, length);
top20.close();
//Processing and Output 2 - Top 10 Batters by Division Report
sortByDivThenBattingAvg(stats, length);
ofstream outTop10("Top 10 Players by Division Report.txt");
printTop10PlayersbyDivision(outTop10, stats, length);
outTop10.close();
//Processing and Output 3 - Offensive Stats by Team Report
sortByTeamThenDiv(stats, length);
ofstream outTeamStats("Offensive Stats by Team.txt");
printOffensiveStatsbyTeam(outTeamStats, stats, length);
outTeamStats.close();
}
// Function Definitions
void swap(MasterData stats[], int x, int y) //sort (x and y for positions)
{
MasterData temp = stats[x];
stats[x] = stats[y];
stats[y] = temp;
}
void sortByBattingAvg(MasterData stats[], int length)
{
//select sort
for (int holdPos = 0; holdPos < length - 1; holdPos++) //Position Holder Loop
{
int maxPos = holdPos; //maxPos is recreated for each iteration of Position Holder Loop
for (int valueFindPos = holdPos + 1; valueFindPos < length; valueFindPos++) //Value Finder Loop
{
if (stats[valueFindPos].battingAvg > stats[maxPos].battingAvg) //Sort
maxPos = valueFindPos;
else if (stats[valueFindPos].battingAvg == stats[maxPos].battingAvg && stats[valueFindPos].sluggingPercent > stats[maxPos].sluggingPercent)
maxPos = valueFindPos;
}
swap(stats, holdPos, maxPos); //Swaps biggest value foudn to holdPos (held position)
}
}
void sortByDivThenBattingAvg(MasterData stats[], int length)
for (int i = 0; i < length - 1; i++)
{
int maxIndex = i;
for (int p = i + 1; p < length; p++)
{
//Sort Logic
if (stats[p].division > stats[maxIndex].division)
maxIndex = p;
else if (stats[p].division == stats[maxIndex].division)
if (stats[p].battingAvg > stats[maxIndex].battingAvg)
maxIndex = p;
}
swap(stats, i, maxIndex);
}
}
void sortByTeamThenDiv(MasterData stats[], int length)
{
for (int i = 0; i < length - 1; i++)
{
int maxPos = i;
for (int p = i + 1; p < length; p++)
{
//Sort Logic
if (stats[p].teamName > stats[maxPos].teamName)
maxPos = p;
else if (stats[p].teamName == stats[maxPos].teamName)
if (stats[p].division > stats[maxPos].division)
maxPos = p;
else if (stats[p].division == stats[maxPos].division)
if (stats[p].battingAvg > stats[maxPos].battingAvg)
maxPos = p;
}
swap(stats, i, maxPos);
}
}
//Prints and Print Helpers
void printTop20Batters(ostream& out, MasterData stats[], int length)
{
printHeaders(out);
for (int i = 0; i < 20; i++)
out << stats[i];
lineA(out);
}
void printTop10PlayersbyDivision(ostream& out, MasterData stats[], int length)
{
int counter = 0;
string currentDivision = stats[0].division;
printHeaders(out); //Prints Headers on top of report
for (int i = 0; i < length; i++)
{
if (stats[i].division == currentDivision && counter < 10)
{
out << stats[i];
counter++;
}
else if (stats[i].division != currentDivision)
{
lineA(out);
out << stats[i];
counter = 1;
currentDivision = stats[i].division;
}
}
lineA(out);
}
void printOffensiveStatsbyTeam(ostream& out, MasterData stats[], int length)
{
int counter = 0;
string currentTeam = stats[0].teamName;
string currentDivision = stats[0].division;
printHeaders(out);
for (int i = 0; i < length; i++)
{
if (stats[i].teamName == currentTeam)
{
if (stats[i].division != currentDivision)
{
lineB(out);
currentDivision = stats[i].division;
}
out << stats[i];
counter++;
}
else
{
lineA(out);
out << stats[i];
counter = 1;
currentTeam = stats[i].teamName;
currentDivision = stats[i].division;
}
}
lineA(out);
}
void printNewMaster(ostream& out, MasterData stats[], int length)
{
for (int i = 0; i < length; i++)
printRecordCSV(out, stats[i]);
}
void printRecordCSV(ostream& out, MasterData d)
{
out << d.playerId << ',';
out << d.firstName << ',';
out << d.lastName << ',';
out << d.division << ',';
out << d.teamName << ',';
out << d.appearances << ',';
out << d.atBats << ',';
out << d.singles << ',';
out << d.doubles << ',';
out << d.triples << ',';
out << d.homeRuns << ',';
out << d.sacFly << ',';
out << d.walks << ',';
out << d.hitByPitch << ',';
out << setprecision(3) << fixed;
out << d.battingAvg << ',';
out << d.OBP << ',';
out << d.sluggingPercent << '\n';
}
void printHeaders(ostream& out)
{
out << setw(11) << "Player ID" << "|";
out << setw(15) << "First Name" << "|";
out << setw(15) << "Last Name" << "|";
out << setw(15) << "Division" << "|";
out << setw(15) << "Team Name" << "|";
out << setw(15) << "Appearances" << "|";
out << setw(10) << "At Bats" << "|";
out << setw(10) << "Singles" << "|";
out << setw(10) << "Doubles" << "|";
out << setw(10) << "Triples" << "|";
out << setw(10) << "Home Runs" << "|";
out << setw(10) << "Sac Flys" << "|";
out << setw(10) << "Walks" << "|";
out << setw(15) << "Hit by Pitch" << "|";
out << setw(15) << "Batting Avg" << "|";
out << setw(15) << "On Base %" << "|";
out << setw(15) << "Slugging %" << "|";
out << "\n";
lineA(out); // line printed for neatness in reports
}
void lineA(ostream& out) //line printed for neatness in reports
{
for (int i = 0; i < 116; i++)
out << "~~~";
out << "\n";
}
void lineB(ostream& out) //line printed for neatness in reports
{
for (int i = 0; i < 116; i++)
out << " ~ ";
out << "\n";
}
//End
↧
December 3, 2014, 5:13 pm
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
1 1 1 1 1
and
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
All help is appreciated
↧
December 6, 2014, 5:40 am
hey everybody. i am a student of Computer Engineering. and i need your helps. i have a homework but its too hard for my programming level yet. please can you help me?
this is my homework:
http://imgim.com/7584incil6017032.jpg
↧
↧
December 7, 2014, 12:11 am
The time it takes to fully prepare a build of an entire game from start to finish can vary wildly depending on several factors (including engine, available build tools, number of platform targets, etc)
How long is your build and what tools do you use to accelerate it?
↧
December 7, 2014, 5:50 am
Hey guys i'm having a little issue here
i need to fill two 2D arrays, the first one with even numbers from 1 to 50, the second one with odd numbers from 1 to 50. Heres what i have
Code:
#include <iostream>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{
srand(time(NULL));
int TA1[8][6];
int TA2[8][6];
int x;
for ( int row=0;row<8;row++)
{ for ( int col=0;col<6;col++)
{
x = rand()%50 + 1;
if ( x%2 != 0 )
TA1[row][col] = x;
}
}
for ( int row=0;row<8;row++)
{
for(int col=0;col<6;col++)
cout<<right<<setw(5)<< TA1[row][col] << " ";
cout<<endl;
}
for( int row=0; row<8;row++)
{
x=0;
for ( int col=0;col<6;col++)
{ x=rand()%50 +1;
if( x%2 ==0)
TA2[row][col] =x;
else continue;
}
}
for ( int row=0;row<8;row++)
{
for(int col=0;col<6;col++)
cout<<right<<setw(5)<< TA2[row][col] << " ";
cout<<endl;
}
}
↧
December 8, 2014, 1:22 am
Hello Everyone,
I want to create 2 different easy processes in C++ 1st and then i wanted to share data between these 2 processes. Kindly help me regarding this assignment.
Thanks
↧
December 8, 2014, 7:41 pm
It runs well now but my I only have 2 problems...
1.even if I press Hi1234 still shows that i need lowercase,upper and number.
2.doesnt recognize the true for the program to end.
PS...i know there are other methods but our teacher told us to use the find() methods.
Code:
#include <iostream>
#include <string>
using namespace std;
bool check_password(const string& password);
bool check_input(const string& password, const string& upper, const string& number, const string& lower);
int main()
{
int length;
string password;
string lower , number;
string upper;
cout << "Write a password: \n"
"Must Have at least one Uppercase letter\n"
"At least one Number\n"
"Please enter 6 - 10 characters: " << endl;
getline(cin, password);
length = password.size();
if(check_password(password) == false)
{
cout << "Must have 6 - 10 digits. Please re-enter your password." << endl;
getline(cin, password);
length = password.size();
}
while (check_input(password, lower, number, upper) != string::npos)
{
cout << "Try Again\n" << endl;
getline(cin, password);
length = password.size();
while (check_password(password) == false)
{
cout << "Must have 6 - 10 digits." << endl;
getline(cin, password);
length = password.size();
}
}
while (check_input(password, lower, number, upper) != string::npos)
{
cout << "Good Job";
}
system("pause");
}
bool check_password(const string& password)
{
if (password.length() < 6 || password.length() > 10)
{
return false;
}
else
{
return true;
}
}
bool check_input(const string& password, const string& upper, const string& number, const string& lower)
{
lower == ("abcdefghijklmnopqrstuvwxyz");
number == ("0123456789");
upper == ("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
if (password.find_first_not_of(upper) != string::npos)
{
cout << "Must contain an uppercase letter." << endl;
}
if (password.find_first_not_of(lower) != string::npos)
{
cout << "Must contain a lowercase. " << endl;
}
if (password.find_first_not_of(number) != string::npos)
{
cout << "Must contain a number. \n" << endl;
return true;
}
}
↧
↧
December 9, 2014, 12:48 am
I use new to allocate a buffer, as follows:
BYTE *p;
p = new BYTE[20];
...
delete p;
After p is deleted, if I do NOT assign NULL to p, is there a way to determine whether it has already been freed?
Thanks
↧
December 9, 2014, 12:50 am
I use new to allocate a buffer, as follows:
BYTE *p;
p = new BYTE[20];
If I do NOT store the size of the allocated buffer, how to determine the buffer size via p only?
Thanks
↧
December 9, 2014, 12:57 am
Hi,
Please read the exercise no.2 of this:
http://books.google.com/books?id=We2...epage&q&f=true
I've written below code for that. I know this code is not complete but this exercise is somewhat hard.
Code:
#include "Simple_window.h"
#include "Graph.h"
#include <iostream>
double curve(double x) {return x*x; }
//---------------------------------------
class FCT:public Shape {
public:
FCT (Fct f, double _r1, double _r2, Point _xy, int _count = 100,
double _xscale = 25, double _yscale = 25): r1(_r1), r2(_r2),
xy(_xy), count(_count), xscale(_xscale), yscale(_yscale)
{
if(r2-r1 <= 0) error("Bad graphing range");
if(count <= 0) error("Non-positive graphing count");
double dist = (r2-r1)/count;
double r = r1;
for(int i=0; i<count; i++) {
add(Point(xy.x+int(r*xscale), xy.y-int(f(r)*_yscale)));
r += dist;
}
}
void reset_orig(Point _xy) { xy = _xy; }
void reset_count(int c) { count = c; }
void reset_r1(double _r1) { r1 = _r1; }
void reset_r2(double _r2) { r2 = _r2; }
void reset_xscale(double xs) { xscale = xs; }
void reset_yscale(double ys) { yscale = ys; }
private:
int count;
double r1, r2, xscale, yscale;
Point xy;
};
//-----------------------------------------------
int main()
try
{
Simple_window win(Point(100,100), 600, 400, "test");
FCT g(curve, -10, 10, Point(200,200), 100, 25, 25);
Text t(Point(200,200),"X");
g.reset_orig(Point(300,300));
win.attach(t);
win.attach(g);
g.reset_orig(Point(300,300));
win.attach(g);
win.wait_for_button();
return 0;
}
catch(exception& e) {
// some error reporting
return 1;
}
catch(...) {
// some more error reporting
return 2;
}
//------------------------------------------------------------------------------
The definition of the
Function is right here (15.3):
http://books.google.com/books?id=We2...epage&q&f=true
I defined a class named
FCT (rather than
Fct, I'll say its reason latter :)). Now the class is defined and is just like the class
Function.
I don't know could I understand the exercise correctly or not.
I DON'T WANT THE CODE. Just guide me how to solve it please.
↧