Answer to Question #241784 in C++ for vishal

Question #241784

Write a C++ program to find the owner name of the hall by hall number using the map.

 

In the main method, obtain input as CSV from the user in the console and find the Hall number to get the Owner of that hall using the map. 

 

Problem constraints:

Create a Map as  map <string, string >

Use find()  to find the hall owner’s name.


Input and Output Format:

The First line of input consists of an Integer 'n' which corresponds to the number of Halls.

The next 'n' lines of Inputs are in CSV format.

For output refer to sample Input and Output for formatting specifications.

 

Sample Input and Output 1:

Enter the number of Halls

4

Enter details of Hall 1:

Hall-230, Binny

Enter details of Hall 2:

Hall-233, Ram

Enter details of Hall 3:

Hall-255, Annie

Enter details of Hall 4:

Hall-240, Vikram

Enter the Hall number to find its owner:

Hall-233

The owner of Hall-233 is Ram


1
Expert's answer
2021-09-25T03:03:36-0400
#include<map>
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main(){
	map<string, string> m;
	cout<<"Enter the number of halls\n";
	int n;
	cin>>n;
	fstream file("output.csv",ios::out);
	string details;
	for(int i=0; i<n; i++){
		cout<<"Enter details of Hall "<<(i+1)<<":"<<endl;
		cin.ignore(80,'\n');
		getline(cin, details);
		cout<<details<<endl;
		file<<details<<endl;
	}
	file.close();
	fstream new_file("output.csv",ios::in);
	string str;
	while(new_file){
		new_file>>str;
	
	
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS