put your markup in code tags please
[ code ]
[ /code ]
put your markup in code tags please
[ code ]
[ /code ]
Wrtie the "itr = strv.begin();" after the cout...
I think when you initialize itr = strv.begin(); at the beginning of the code the itr points a random value at memory and when cout attempts to write this value it causes an error.
But when you initialize the "itr" after the loop, the "itr" points the first user defined element in the list and when cout attempts to output this value it doesn't cause an error...
you are correct in that it fails if you assign the itterator before you have placed any values into the vector.
found the second bug
while( str_time.substr(14,2) != "00")
{
str_time = format_time( input_time );
input_time -= 60;
}
the reason this is incorrect is because the output time is formatted before the new time has been calculated thus the str_time format time will always be incorrect. the loop would continually get stuck forever.
use this
cout << (*itr++).c_str() << endl;
i will check it but also you should try running it a few times to see what happens.
EDIT:
also please include any headers and other functions you may have defined :)
not to be rude but your models/environments dont show much but the same item composed of simple primitives copied over and over again.
not enough variation in your work.
fastest method
string splitme = "foo,bar,feet,meet,meat,skeet";
ArrayList gatherSplit = new ArrayList(splitme.Split(new char[] { ',' }));
You end up removing the fourth character instead of the third one. Doing
if(i % 3 == 2)
would solve the problem.But I still think that removing third character from each _word_ is different from removing third character from the string as a whole.
Hello World
Helo Wold
Heo Wod
He Wo
awesome, i hadnt had the time to really check to see how accurate the work was i just understood the general concept.
i believe he wants to remove the third character from the string a whole not the words idividual
re-read his thread he does state
every third character of the string
so i went with that idea.
im not tired of you yet (but dont think i cant get there lol) so i will try to help you.
first of all you need to comment your code up when you expect help. Without comments we really dont have a direction in which to begin helping you because then we have to spend valuable time learning your code!
But i digress this is a simple snippet i believe i may be able to help you with it :-D
Question 1: number of test scores (easy i believe you already have that) BUt i also noticed that you are assigning the array size to a const 60 but what does your application do if there are 40 grades or even 100 grades, this can drastically throw off the calculation.
One option is to use vectors
#include <vector>
int main() {
vector<int> testScores;
while(!infile.eof()) {
int temp;
infile >> temp;
testScores.push_back(temp);
}
using vectors you can now have a container for any ammount of grades
and to get the size or number of elements (grades)
int testScoresSize = testScores.size();
Question 2: average of the test scores!
very simple with vectors
int sumofScores = 0,
totalScores = testScores.size();
for (int i = 0; i < totalScores; i++)
{
sumofScores += testScores.at(i);
}
int averageScore = sumofScores / totalScores;
//i am using an int but if you wish to have more percision you may want to use a different data type.
Question 3: …
i started at 1 because the modulus of 0 and 3 will return 0 because zero divided by anything is zero and i do not want to remove the first character.
also the logic is wrong in your code, with your current example only removes the character in the third position it does not remove every third character.
something like this creates close to what you are asking
// string_manip.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;
void removethird(string text) {
cout << "Removing every third character until less than or equal to six characters remain" << endl;
while (text.length() > 6)
{
for(int i = 1; i < int (text.length()); i++)
{
if (i % 3 == 0) // divisible by three 3,6,9,12,15,18...etc
{
cout << text.c_str() << endl; //show me the string
text.replace(i, 1, "\x0"); //replace the character with a null character
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
string foo = "HELLO WORLD";
removethird(foo);
return 0;
}
try naming your functions relevant to what they do. i will go through this now and see what i can do to help you though :)
My guess is you could maybe use it for understanding the process/concepts but i doubt you could get much more than that.
PHP has much language syntax that mimics C++ but i doubt i could use PHP as an entry into C++ :)
go to the MSDN website and look up the function you will find everything you need.
Here are two working methods to store your return from a message box, using the C++ API version and the .NET Version
/* WINDOWS API VERSION
MessageBox (
HWND Owner,
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType);
*/
int messageResult = MessageBox( NULL, L"SOME MESSGE", L"Some Title", MB_OK);
if (messageResult == MB_OK) {
//what to do with our result
}
/*.NET VERSION
MessageBox::Show(
string Message,
string Caption,
MessageBoxButtons Buttons,
MessageBoxIcons Icon);
*/
DialogResult myResult = MessageBox::Show("SOME MESSAGE", "SOME TITLE", MessageBoxButtons::YesNo, MessageBoxIcon::Information);
if (myResult = DialogResult::Yes) {
//should work
}
i've tested the C++ API version and is working, the .NET Version works fine in C# (i dont have a project open right now in C++ using the .NET namespaces) but following the same logic it should work.
if not shame on me lol
this is the usual method i use for a message box
if ( MessageBox::Show("Some Message",
"Some Title",
MessageBoxButtons::YesNo,
MessageBoxIcon::Information) == DialogResult::Yes) {
//write the code to do what i need
}
Seems like someone asked the question, some else read read the answers and followed up with more question and finally someone understood all and thanked. :)
If solved mark the thread as solved..
the information provided in this thread has been an awesome resource.
at first i was going huh? ** or *& but now it makes sense to me :-D
http://www.cplusplus.com/doc/tutorial/pointers.html
is a recomended read for anyone confused about pointers.
i read this site one nite and had somewhat of an epiphany lol
the site helped me to understand pointers and their usefullness.
I haven't yet started this assignment for I have to submit my E.V.S PROJECT within the next 2 days , so I am really busy in that.
On another note, I wanted to know what are actually random nos., because I have often seen all of you using it quite a many times.
what are random numbers?
just that random numbers :D
http://www.daniweb.com/forums/post394829-10.html
this is an array pointer example i wrote, but it deals with random numbers :)
If you are still interested a few things you could do / should do.
get an XML Parser and treat all pages like XML, since HTML follows a strict coding format (or at least properly built pages do) you could easily build a parser using an XML tool.
Secondly since it is going to be command line i am assuming no reason for graphics, so again it's just a matter of parsing the text and other style/placements
but then you get into the issue of the Styles.
because the grounds on how each browser displays is so poorly implimented by each side (microsoft,firefox,safari...etc) it would be in your best interest to look up the DOM (document object model) as well as http://www.w3.org/ as they are the people that set forth the guidlines.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Odbc;
namespace ConnectionSharing
{
class SqlConnectionManager : IDisposable
{
public SqlConnectionManager() {
if (ConnectionSharing.Properties.Settings.Default.OdbcSqlConnection == null)
{
//you may place any initializer code in here
//create our connection string
/*
* Driver: The built in Driver to use, for
* non standard databases this must
* be installed and setup prior to calling
* Server: The location of the server, mine
* happens to be on the local host
* Database: Not specified but is recommended
* if you wish to use for specific reasons
* Uid: The user ID of the person connecting
* specified by the global variables
* Pwd: The password of the person connecting
* specified by the global variables
*/
string openSqlConnection =
@"Driver=(SQL Server);Server=Localhost;uid=" + ConnectionSharing.Properties.Settings.Default.Username +
";Pwd=" + ConnectionSharing.Properties.Settings.Default.Password + ";";
//please note that the @ sign on the preceeding line means to interpret the string literally
this.x_sqlConnection = new OdbcConnection(openSqlConnection);
}
}
//now any methods you create have access to the SQL connection created
private OdbcConnection x_sqlConnection = null;
//always supply a dispose method when working with disposable objects
public void Dispose() {
//cleanup / close the connection
this.x_sqlConnection.Close();
this.x_sqlConnection.Dispose();
}
}
}
you can now reference this class from any other form/class you create and not have to re-write your code for common tasks.
one option would be to create another application setting which contained the OdbcConnection object this way each time the class was called from a new form it would …
when in the C# Editor add a new class,
build that class as you need.
then you can simply reference that class in any other class/form as needed.
i'll write you an example write now!
cheers! :-)
EDIT:
Also if you have any questions regarding what you are trying to acheive i may be able to point you in a direction that will reduce the ammount of code you are using.
One huge advantage of C# is that it can use libraries from most any languages as long as they are built correctly. I find myself most commonly referencing C++ libraries to handle tasks that would otherwise require more code than normal.
Thank you so much for the SUPERB explanation .
Now I would try out a program that implements insertion sort and see to it whether I am successful .
Loads of thanks once again. :)
now it's time to write your own insertion method :D
no better way to learn than with your very own hands :)
First of all it is Node not Nod.
the only way to add check boxes to the node tree is by specifying it on the TreeView object itself, thus all of the nodes will have checkboxes.
but in your example it would be
treeView1.CheckBoxes = true;
another method (if you are seeking to only have it on a few and not the entire tree) is to use an image list and keep track of which nodes are visually marked with your custom check or not.
repost that using the code tags
[ code="csharp ]
your code here
[ / code ]
without the spaces of course.
i ran into an issue such as this a while back and ended up just writing a library to handle all SQL connections so that all forms had a central method for running their methods.
based on these two methods is there any gain over one, is one safer than another?
Could You give me a little example(C#), so i`ll try to continue
Thanks
you should really try to gain an understanding of what you are trying to do.
in about 30 seconds of google searching i was able to find examples of what you need to do.
hint an IP with a PORT is called a socket
so look up C# and sockets.
now that im awake i will try to explain this some more lol! :D
#include "stdafx.h"
#include <cstdlib>
#define length(a) (sizeof a / sizeof a[0])
i've included the cstdlib to gain access to rand and RAND_MAX so i can generate some random numbers.
Also note the define, i have created this define to find the length of an array, since the sizeof returns the byte size of something and not the actual number of elements i need to get the actual byte size of an int and the the array and divide em out to get the total number of elements (or so i believe that is what is going on lol)
void ArrayGenerator(int * MyArray, int ArraySize) {
int lowest = 1,
highest = 50,
range = (highest - lowest) + 1;
the lines lowest, highest, and range are used to generate random numbers within a certain area, i just happened to want numbers between 1 and 50, you could very easily modify the function to require arguments specifiying the range
//act like we are generating random numbers
for(int i = 0; i < ArraySize ; i++)
{
*(MyArray + i) = lowest + int(range * rand() / (RAND_MAX + 1.0));
}
}
these lines are pretty simple, while im less than the array enter a random number into the array at the pointed too position
*(MyArray + i) states to go to the location pointed at plus whatever 'i' is.
int _tmain(int …
What have you written so far?
try writing some pseudo code first :)
you will want an IP
and a specific range of ports to check.
you will need a method for sending a ping to them and a method for listening for a response (three part handshake for networking peeps)
you should start by writing something that can ping a local address, or even just something that can connect to a local machine to get the feel for how networking works.
I this is solved but if you are using the newer version of express 2005 you can simply create a masked textbox that only accepts INT values
some code i wrote that basically does what you spoke of
#include "stdafx.h"
#include <cstdlib>
#define length(a) (sizeof a / sizeof a[0])
void ArrayGenerator(int * MyArray, int ArraySize) {
int lowest = 1,
highest = 50,
range = (highest - lowest) + 1;
//act like we are generating random numbers
for(int i = 0; i < ArraySize ; i++)
{
*(MyArray + i) = lowest + int(range * rand() / (RAND_MAX + 1.0));
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int FillThisArray[10];
int * fillArray = FillThisArray;
ArrayGenerator( fillArray, length(FillThisArray) );
return 0;
}
this function takes a pointer to an array so i can write code and pass it an array and have it modify the original array and not have to worry about returning anything.
It's pretty neat and now i think im going to go to bed, it's 1:30 in the morning :-X
sorry if it's a bunked (what i said) as i am tired right now :-P
without booring you too much or reapeating valuable information already posted i will tell you how i began to understand arrays.
when i first started programming i had no idea what they were or how they worked untill i started thinking about them like this
Boxes.
as simple as that
so when someone said i had an int array that was 6 in size i would simply allocate six boxes in my head
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
just like that. I would even draw it on paper and test my statements by doing them by hand and drawing lines between the boxes.
it helped me tons to see how one could manipulate the data within them and how they can be a powerful resource if used correctly.
let's see some of your examples. looks like you will be working with some basic arrays and file reading.
probably wont be much in the ways of memory to hog unless you are talking about reading thousands of students at once :P
i cant think of a better resource than http://www.msdn.com for all your programming needs really. when you find what you are looking to do if you need examples this is teh place to come to. I use MSDN for pretty much all of my research.
Personal Books i found of value:
C# Pocket Reference
not bloaded with extra crap, clean and to the point, covers exactly what you need to get started.
Wow.. 7 or 8? You started early lol.
well my dad has always been a software engineer/architect his whole life, and just recently moved to product research/development so he's been a major influence in my life and an awesome resource for questions on how things are done in the real world.
I want to be you.
dedication is key!
i started to tinker with computers...well for as far back as i can remember i have been tinkering with computers...Thats near 12 -13 years of computer experience, starting way back in the days when i was around 7 or 8.
The first OS i remember is 95 but my dad has a copy of every windows OS ever released and some linux distros (even though he never uses them).
I started messing around with programming around the 6th or 7th grade, not sure, but was the first time i started writing code in the C language followed very shortly by C++. And since then it has been dedication that really keeps my working hard at what i do.
Work hard, play hard, and have fun is the key :)
Right now i get payed to write in C#, i could just as easily do VB but I find the syntax of that language to be broken and poorly written.
I also get paid to do web work using easier scripting languages like PHP, Javascript, HTML..etc
dilligence lol
Yes Maya is built in C++. As for your first answer you just made me more confused then I was when I first asked the question.
i believe he is trying to say that if and when you write this DLL and begin testing since you cannot execute/run the DLL you need to write in your own tests to make sure that you are correctly passing the data at each step.
Also i believe VB can call C++ DLL's as you can use the System.Runtime.Interop namespace to reference DLL's into ones app. correct me if i am horribly wrong :D
this is an odd error yes. because when i debug your code it works as desired. but the moment i remove the breakpoint and allow it to run we have issues again!
but i was able to create a quick fix for you!
create the random number on the Update method and then simply pass the output to the RandomColor on each itteration.
I cant give you a clear answer as to why your first method does not work but i believe it has something to do with the scope in which it is being called.
another solution is to create a private Random variable outside of the method
Class Utilities
{
private Random rand;
public Utilities() {
rand = new Random();
}
public Color RandomColor() {
switch(this.rand.Next(1 , 8);
//rest of your method
}
}
as this works just as well and keeps the random inside the class.
I'm writing a peer to peer network in c# with .net 3.
I'm using a tcp/ip architecture where each device acts as both a client and a server.
If one pc wants to download a file from another, how will it know what port the server on the other pc is listening on?
Because they both need to connect to the same port for a connection to be made
for this you should really understand the OSI model and how router works.
i would give you more but there is only so much i can say.
Where did you go? And what degrees did you earn?
Heald for first college and got my AAS in IT (i regret the school and not the degree though)
working on either UoP or CSU Stan to get BS, im looking into physics and chemistry now though.
lol.. well, I hope college will provide me with that education :)
been there done that and working on going back as well. College is a great experience and helps open up many doors that would otherwise be closed to most.
hah.. cool. There is hope for us noobs I guess ;)
lol, there may be hope yet!!
just takes a lot of time and dedication :)
lastnight when browsing daniweb i realized something.
when i first started browsing this site back around 2004 i was offering PC troubleshooting support. I spent most of my time on this site offerent support for others at zero cost because i love to do that sort of thing.
Around that time i was dabbling in C++ and other languages and the thought of doing that full time was just that, a though.
Now today three years later I'm being payed very good money to develop software on a daily basis and I love it.
Just funny how my computer skills have evolved so much. I want from a young fledgling noob that liked to tinker with computers to writing software for clients :lol: all that I just turned 20 this year :icon_eek:
Say I have some software and I have it all finished and everything, how do I go about getting it into shops? How do I go in a and talk to them? I don't mean shops like PC World (yet anyway) I mean my local PC shop. How do I get bar codes sorted? How do they work? What do I say to the people in the shop, do I let them look at the product? Do I give them x number as a free trial? How many should I produce at a time? Help?
mistake number one. assuming it is finished.
i can guarentee that for every 100 users 99 of them are going to find a way to break it that you didnt think possible.
you just need to provide the product.
and your best bet of selling it, walk in cold sale or build a relationship with the owner.
There's no general ratio. If you're expecting one, you'll be waiting until somebody spends his life doing benchmarks.
so true, the client i work for is constantly asking for well if it is going to x ammount of time to develop this how long do you think it will take to maintain/debug etc...
it's hard to tell him that no project can really ever be complete because you will probably be maintaining it for a long time :lol:
i love doing it though so i dont mind, and the pay is great so yay for meeeee :D
so as i gather it you have this rich text box on your main form,
you want to be able to process information from one class and have it output on your main form? IE:
class MyMainClass : Form
{
public partial class MyMainClass()
{
InitializeComponent();
//your initializer code here
}
private void someButton_Click(object sender, EventArgs e) {
//from this button we will call another classes function?
//what this class returns needs to be placed into our text box
}
}
class CustomFunction
{
public CustomFunction()
{
//some initializer code here
}
pubic string SomeFunction(string foo, string bar) {
}
}
so as i gather it (i may sound a bit repetative here :lol: ) you want CustomFunction class to modify the contents of our main form?
if so that is much simpler than it may seem.
you can create a function with a return type (like that of SomeFunction) and call it from your main class and store its returned value into your richtextbox
if however i seem to be missing what you are saying just let me know :D
code would look similar to this
class MyMainClass : Form
{
public partial class MyMainClass()
{
InitializeComponent();
//your initializer code here
}
private void someButton_Click(object sender, EventArgs e) {
//from this button we will call another classes function?
//what this class returns needs to be placed into our text box
this.richTextBox1.Text = new CustomFunction().SomeFunction("shorter", "LongestString");
}
}
class CustomFunction
{
public CustomFunction() …
post some of the code that you have, what you need to do is make sure that the text box you are printing to is public.
also you may run into some issues with the fact that you are working between two different classes see.
we come into scope issues really (i dont quite know a better way to explain it).
class myForm : Form
{
//some designer code with form stuff
}
class modifyForm
{
//some methods to modify the myform class
}
now if your myForm is called from something else, IE it starts when the application loads then myclass is going to run into issues such as
myForm modifyForm = new myForm();
because the moment you do that you are instantiating a new copy of the myform so any changes you make to this form are not going to be recognized by the old form.
so one possible method is to work with a global setting for the RichTextBox
IE go into the properties/settings and add a new settings type. then on either form add an event type that watches for the change of settings and update the box as needed.
but there are other methods of doing this.
the most basic method is this
class MyFirstClass : Form
{
//intializer
public MyFirstClass()
{
//your initializer code
}
public void OpenNextForm() {
ModifierClass foo = new ModifierClass(this);
foo.Show();
}
}
//assume we are another file, or just further …
are you trying to refresh a part of the application that is not directly associated with the thread?
this is common and can be a pain in the but to fix.
if you would like to share a sample of your code i may be able to help you write in some thread saftey.
what do you mean how to recognize the computer move?
you are writing the code that will basically control the AI for the computer.
what you need to recognize is when the players turn is over so you can start your AI which would be simple.
you are controlling the user input when that is done you can call your methods to manpilate the gameplay.
since it is tic tac toe you might be playing on a 3x3 board IE 9 spaces (that is if you are going for three in a row)
you can simply poll all of the spaces to see what is taken and what is not and randomly generate an X or O appropriately in an empty space.
or if you can program in some general strategies and the ability to understand and recognize them.
IE if spaces 1 and 2 are checked and are checked by the enemy then they are about to get a victory, place computer check in space three
that is assuming the layout is
123
456
789
with that same logic you could program in
if 7,5 is taken make sure to take 3 so the user cannot win
or if 7,5,9 is taken make sure to take the space that will ensure the most saftey based on current moves...etc
good luck!
public class ManageDigits
{
/// <summary>
/// when the class is called the array is built for the first time
/// </summary>
public ManageDigits() {
x_DigitSearchedFor[0 , 0] = string.Empty;
x_DigitSearchedFor[0 , 1] = string.Empty;
x_DigitSearchedFor[0 , 2] = string.Empty;
x_DigitSearchedFor[1 , 0] = "One";
x_DigitSearchedFor[1 , 1] = "Eleven";
x_DigitSearchedFor[1 , 2] = "Ten";
x_DigitSearchedFor[2 , 0] = "Two";
x_DigitSearchedFor[2 , 1] = "Twelve";
x_DigitSearchedFor[2 , 2] = "Twenty";
x_DigitSearchedFor[3 , 0] = "Tree";
x_DigitSearchedFor[3 , 1] = "Thirteen";
x_DigitSearchedFor[3 , 2] = "Thirty";
x_DigitSearchedFor[4 , 0] = "Four";
x_DigitSearchedFor[4 , 1] = "Fourteen";
x_DigitSearchedFor[4 , 2] = "Forty";
x_DigitSearchedFor[5 , 0] = "Five";
x_DigitSearchedFor[5 , 1] = "Fifteen";
x_DigitSearchedFor[5 , 2] = "Fifty";
x_DigitSearchedFor[6 , 0] = "Six";
x_DigitSearchedFor[6 , 1] = "Sixteen";
x_DigitSearchedFor[6 , 2] = "Sixty";
x_DigitSearchedFor[7 , 0] = "Seven";
x_DigitSearchedFor[7 , 1] = "Seventeen";
x_DigitSearchedFor[7 , 2] = "Seventy";
x_DigitSearchedFor[8 , 0] = "Eight";
x_DigitSearchedFor[8 , 1] = "Eighteen";
x_DigitSearchedFor[8 , 2] = "Eighty";
x_DigitSearchedFor[9 , 0] = "Nine";
x_DigitSearchedFor[9 , 1] = "Nineteen";
x_DigitSearchedFor[9 , 2] = "Ninety";
}
/// <summary>
/// depending on how this is used i may set it readonly
/// this will prevent you from writing code that accidentally modifies
/// the values within the array
/// </summary>
private string[,] x_DigitSearchedFor = new string[10 , 3];
/// <summary>
/// gets the position of the array at the specified points given
/// </summary>
/// <param name="PositionOne">first integer position</param>
/// <param name="PositionTwo">second integer position</param>
/// <returns>returns the position as string</returns> …