944,133 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4119
  • C++ RSS
Feb 4th, 2005
0

Need help starting program using vector

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
roscioeak@direc is offline Offline
8 posts
since Feb 2005
Feb 5th, 2005
0

Re: Need help starting program using vector

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

#include <iostream>
#include <vector>

int main()
{
using namespace std;
vector< pair<int,double> > Dim;
vector< pair<int,double> >::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;
}
Reputation Points: 10
Solved Threads: 1
Light Poster
Intel is offline Offline
30 posts
since Feb 2005
Feb 5th, 2005
0

Re: Need help starting program using vector

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
roscioeak@direc is offline Offline
8 posts
since Feb 2005
Feb 6th, 2005
0

Re: Need help starting program using vector

No problem ...
Reputation Points: 10
Solved Threads: 1
Light Poster
Intel is offline Offline
30 posts
since Feb 2005
Feb 8th, 2005
0

Re: Need help starting program using vector

Intel:

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

http://daniweb.com/techtalkforums/an...nouncementid=2
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: Help... assembly in Dev C++
Next Thread in C++ Forum Timeline: editor design using c..help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC