954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help starting program using vector

This is my first post here and so far I have been doing fine in my last C++ class but right now I am stuck. I have to make a program using an array that is initialized dynamically. You have to make a program that will input the rooms of a house;n, and then ask for the user to input the size of each of the rooms until it is done. Then you have to scan the array for the largest room and output its dimensions. I know that you have to do it as a vector so that you can input the data. I just have no idea on how to start this. Please help.
Anthony

roscioeak@direc
Newbie Poster
8 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

HERE ................

#include
#include

int main()
{
using namespace std;
vector< pair > Dim;
vector< pair >::iterator itr,largest;
int Rooms(0), W, H;

cout << "Rooms of a house :>";
cin >> Rooms;

cout << "Dimensions format : W * H" << endl;
for (int i=1 ; i <= Rooms ; ++i) {
cout << "Room "<< i << " Dimensions:> ";
cin >> W >> H;
Dim.push_back( make_pair(i,W*H) );
};

largest = Dim.begin();
itr = Dim.begin()+1;
while (itr != Dim.end()) {
if ( (*itr).second > (*largest).second)
largest = itr;
++itr;
};

cout << "Room " << (*largest).first << " With Dimensions Size " << (*largest).second
<< " Is The Largest Room" << endl;
return 0;
}

Intel
Light Poster
30 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

Thanks, INTEL
I didn't expect to get that much but now that I see it now I will be able to figure out everything and learn that way.
Anthony

roscioeak@direc
Newbie Poster
8 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

No problem ...

Intel
Light Poster
30 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

Intel:

Do not do people's homework for them. Please read this:

http://daniweb.com/techtalkforums/announcement.php?f=8&announcementid=2

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You