| | |
Need help starting program using vector
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2005
Posts: 8
Reputation:
Solved Threads: 0
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
Anthony
•
•
Join Date: Feb 2005
Posts: 30
Reputation:
Solved Threads: 1
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;
}
#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;
}
Intel:
Do not do people's homework for them. Please read this:
http://daniweb.com/techtalkforums/an...nouncementid=2
Do not do people's homework for them. Please read this:
http://daniweb.com/techtalkforums/an...nouncementid=2
Alex Cavnar, aka alc6379
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Help... assembly in Dev C++
- Next Thread: editor design using c..help
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





