anything will help! If you can even just tell me what it means when the shapes are drawn like this!

Hey everyone,

I'm new at visual c++ and MFC Applications, and so I am going through Ivor Horton's Beginning Visual C++ 2010 to make a drawing application through Microsoft Foundation Class.

I added menu bars for options, such as shape(rectangle, line, and ellipse) and select colors (black, red, blue green).

I have added message handlers to the program that makes it so that you can select different menu options like rectangle & blue, or ellipse & black. And I am at the point where the drawer can click LButtonDown to set the first point and the LButtonUp to release the second point.

But, I am having a problem when I try to draw any shapes where it records every mouse move so that it doesn't just record the first and second points, which I believe is called rubber banding?

I have attached my MFC GUI to this thread if anyone wants to take a look at what the shapes look like when drawn. THE TOP LEFT ARE RECTANGLES, THE BOTTOM LEFT ARE CIRCLES, AND THE BOTTOM RIGHT ARE SUPPOSE TO BE LINES..

And here is a couple of the important functions:

[CODE]CElement CBoxView::CreateElement(void)const{
// Get a pointer to the document for this view
pDoc = GetDocument();
ASSERT_VALID(pDoc); // verifies that the pointer is good

// Now select the element using the type stored in the document
    return new CRectangle(m_FirstPoint, m_SecondPoint, pDoc->GetElementColor());
    return new CEllipse(m_FirstPoint, m_SecondPoint, pDoc->GetElementColor());
case LINE:
    return new CLine(m_FirstPoint, m_SecondPoint, pDoc->GetElementColor());
default: ...

Thanks for the help everyone. I appreciate it.

Hey everyone,

I have to manipulate two functions RECURSIVELY, strlen and strcpy.

I was able to code the strlen:

[CODE]int length(char* str){
if(str == NULL){
return 0;
return length(str, 0);

int length(char* str, int l){
int len=0;
len = length(str,l+1);
} else {
return l;
return len;

But I am having a lot of trouble with even beginning the strcpy function:

[CODE]char copy(char old_str, char new_str){
if(old_str == NULL){
cout << "Could not copy, string is empty\n";
return -1;



Here is my input on Strcpy:

  • The base case can return -1 because you shouldn't have to copy nothing over to a new string.
  • For the Recursive call, I have to go through the old_str recursively.

I appreciate all of the help.

Thank you.

thanks rav, you always give great tips and information.

So after the information is in the parallel vectors, i can then use the original algorithm for sorting the GPAs ascending? Or is there a method that I am not aware of?

Thanks again!

i have to read in a file though. Is it possible to use push_back by doing the following:

in >> (string) temp1
in >> (double) temp2



What I am trying to get at first, is to stream the file onto 2 parallel variables, then maybe use push_back to store the variables onto 2 parallel vectors?!

I just did some researching on it, but tell me if that sounds right.

Hey everyone,

In my COMP 208 class, I was asked to do the following:

"Redo Lab 2 Problem 2, only this time use vectors to hold the names and gpa’s instead of arrays. So you will work with 2 vectors, one holding the gpa’s (type double) and the other holding the names (type string)."

"Your program sorts the students ascending by gpa, and prints the sorted list including names. To keep the names with the numbers use parallel arrays, one for the names, the other for the numbers. Sort the numbers. Whenever you swap 2 numbers also swap their matching names in the names array."

I've already coded with arrays in this problem, but now my teacher is asking me to replace the arrays with vectors. The only problem is that we haven't gone over the least bit of vectors, and all I know from research is that vectors are inter-changeable, can be re-sized throughout the program, etc.

I'm asking for help on how to go about changing the student[] and studentGPA[] into vectors and if there is any other importance to vectors, let me know!

Any help would be great, and here is my code for the original w/arrays:


Write a program that reads names and gpa's from a text file (TextFile1.txt).

The program will:
- sort the students from lowest gpa to highest.
- print the sorted list, including names.

Use 2 parallel arrays, one for ...

new code, less sloppy..

[CODE]#include <iostream>

include <fstream>
include <string>

using namespace std;

int main(){

//open file (each name is on its own line)
fstream in;
char word[256];
cout << "I will Alphabetize file TextFile1.txt" << endl;

return 0;


void extractNames(fstream& in, char word[]){

cin.getline(word, 255, '\n');


swap(fileNames, intitialNames,swappedNames) //puts word into the array

void swapNames(char words[], string intialNames[], string swappedNames[]){

//use bubble sort to sort the strings by last name (works fine with strings)


The question is:

A file contains a list of names in the form:

Jones, Frederick M
Brennan, Claire

Your program should alphabetize the list. Use the C++ string class. Also, extract names from the input stream with getline().

What i know so far:

main() should declare a char array and to open a requested file from the user

extractNames() should print out what file is being alphabetized and use cin.getline() to stream in the file into my char array, line by line.

swapNames() should use a sorting method, maybe bubble sort, to pass in the char array as an int array to make it easier, and alphabetize each line according to the algorithm suggested for alphabetizing..

Question 1.will cin.getline()only stream in 1 line, instead of cin >> file, and if so,how do you go about this with alphabetizing.. What I am thinking is: cin.getline() will stream in 1 line, maybe at a time, and then you can call the swapNames function after the first cin.getline(), and if that second line's first int is smaller than the first lines, switch the second line to the first.

Question 2. How do i go about converting the char array that has the text file in it, into integers. I've never had to do this, and I've heard it makes the process easier using int.

Here is my CODE:

[CODE]#include <iostream>

include <fstream>
include <string>

using namespace std;

int main(){

//open file (each name is on its own line)
fstream in;
char fileNames[256];
in.open(fileNames); ...

When I try and do:

in [COLOR="Red"]>>[/COLOR] student >> studentGPA;

I am getting an error "no operator ">>" matches these operands.

Hey Walt,

I respect your response and all, but I was just trying to explain as detailed as possible what I needed to do.

Your answer to my last question leaves me without a clue of what to code, and what do you mean by "thats easier and faster than posting on a forum"?

Hey ravenous,

I have a question about:
infile >> names[i] >> grade [i];

Will this go through the first line of the file and put the name in names[] and the gpa in grade[], then repeat with i++?

After this part, I need to order the array so that it is in ascending order, meaning that the lowest gpa goes first with the correct name, followed by the 2nd lowest gpa with the correct name, ect.

I have to swap gpa[0] and gpa[2], which means doing the same thing to names[0] and names [2]. How do I make a swap?

Thanks for all the help guys.

my first problem I need to resolve is to actually put the correct data into both arrays. How do i store the names in one, and the numbers in the other array if their both in the same file?

Hey everyone,

I need to write a program that reads names and GPA’s from a text file. The file looks like:

James 3.9
Margaret 3.5
Charles 1.2
Jennifer 4.0

The program sorts the students ascending by gpa, and prints the sorted list including names. To keep the names with the numbers use parallel arrays, one for the names, the other for the numbers. Sort the numbers. Whenever you swap 2 numbers also swap their matching names in the names array.

The only thing that I've done so far is to open the text file and created a function called:
[INDENT][/INDENT]gpa_sorter(istream& in,string student[200],double studentGPA[200])

I don't know how to even write the pseudo code after while(!in.eof()) because im confused about sorting the data from in the file into 2 separate arrays, one that is double and one that is string.

Also, I'm not allowed to use vectors yet, and if you could please describe it to me as simple as possible in pseudo code, that would be great because i'm only in my first year.

Thanks again.

alright thanks for the help. what are code tags though.. comments?

Hey guys,

This is only my second thread on DaniWeb and I am a beginner programmer.

My code looks like this: (really easy to understand and shouldn't need any further explanation besides the fact that I need help understanding why when i give an answer related to the 'else' loop, it says what is needed, but gets stuck in an infinite loop!)


include <iostream>
include <string>

using namespace std;

int main() {

char answer;

cout << "do you think megan fox is hot? <y/n> "<<endl;

do {

if (answer == 'y' || answer == 'Y')
    cout<<"You are the man"<<endl;
else if (answer == 'n' || answer == 'N')
    cout<<"What is wrong with you?"<<endl;
    cout<<"answer the question with a 'y' or 'n' please."<<endl;
} while (answer == 'y' || answer == 'Y' || answer == 'n' || answer == 'N');

return 0;


thank you for the extremely helpful advice on cout, and also for fixing my problem!

I'm new to visual, and so I was trying to organize my tutorial coding into my 'Arrays' source files, but I guess you have to separate main programs?

When I try to build it, I am getting an error '_main already defined in basic array.obj'

I don't see whats wrong with the code..

Hey guys,

This is my first official post on DaniWeb :)

I am new at programming in C++ using visual studios, and right now I am fooling around with storing user input into Arrays.

I am having a problem with my code, using an array size of 3 to store the users input into the first 2 spots [0 and 1] and then making a calculation in the 3rd spot[2].

Here is my code:

[CODE]#include <iostream>

using namespace std;

int main() {

double userInput[3];        //array can only hold *3* elements

cout<<"Enter the number of cars you wish to buy: ";
cin>> userInput[0];         // users input stored into array 0

cout<<"Enter the amount of money you wish to spend for one car: ";
cin>> userInput[1];

//the last array will times the number of cars you wish to buy times
//the amount you wish to spend for one car.
//the value will be stored in the last array

userInput[2] = userInput[0] * userInput[1];

cout<< "According to my calculations... If you were to buy "<<userInput[0]<<" cars, for $"<< userInput[1]<<" each, then the total money you will spend will be $" <<userInput[2]<<endl;

return 0;


P.S. How can I spread out the last 'cout' of my code onto multiple lines without disturbing the build so that it works!?

Thanks guys and I hope to hear a respond very soon!

  • Ben.