num 3 in c ++
answer it as simple as possible with no complicated codes, please
A C++ program is as follows,
File name: “main.cpp”
//Define header files
#include<iostream>
#include<string>
#include<map>
#include<fstream>
#include<iomanip>
using namespace std;
int main () {
// store the names in a map
std::map<std::string, float> marks_db;
std::string in_file_name, out_file_name;
std::cout<<"Enter input file name: ";
//Get the input file name
std::cin>>in_file_name;
std::cout<<"Enter output file name: ";
//Get the output file name
std::cin>>out_file_name;
std::fstream in_file, out_file;
// open files for respective operations
in_file.open(in_file_name.c_str(), ios::in);
out_file.open(out_file_name.c_str(), ios::out);
// check for file opening status
if (!(in_file.is_open() && out_file.is_open()))
{
std::cout<<"Couldn't open file/files.\n";
return -1;
}
std::string name = "";
std::string marks = "";
// Read the file and store the details in the map
while (!in_file.eof())
{
in_file >> name;
in_file >> marks;
marks_db.insert(std::make_pair(name, stof(marks)));
}
// Close the input file
in_file.close();
float cut_off;
std::cout<<"Enter the threshold mark: ";
std::cin>>cut_off;
// apply the cut off for the given database
std::map<std::string, float> :: iterator it;
for (it = marks_db.begin(); it != marks_db.end(); ++it) {
//Check for the pass mark
if (it->second < cut_off) {
continue;
}
// print to output file with iomanip formatters
out_file.fill(' ');
//Set the width for the names to "8"
out_file.width(8);
out_file << it->first << " ";
//Set the width for the marks to "7"
out_file.width(7);
//Set the decimal digit to "2" and print to output file
out_file << setprecision (2) << fixed << it->second <<"\n";
}
// close the output file
out_file.close();
}
Input file: "total.txt"
Screenshot #1:
Screenshot #2:
Screenshot #3:
Step by stepSolved in 3 steps with 6 images
- The question should be done in C++, please give explanation and running result. 1. Let’s write a function that compares 2 strings and returns true if they were identical, false otherwise. The signature of this function should be: bool word_diff(std::string word1, std::string word2); For example: std::string str1 = "Hello World";std::string str2 = "hEllO World";std::string str3 = "World";std::string str4 = "Hello World";bool result = word_diff(str1, str2); // Falsebool result = word_diff(str1, str3); // Falsebool result = word_diff(str1, str4); // True 2. Now let’s follow a classical approach to compare the content of 2 files. We should open each file, read their content word by word and compare them until a first mismatch occurs.Let’s implement a function called classical_file_diff that takes 2 arguments each of which is a file name and returns a boolean indicating whether the 2 files are identical or not. The signature of this function should be: bool…arrow_forwardWrite code in C++ There are two scientists working on set of numbers. The first person is looking for two numbersspecifically. The second person is responsible for entering all data. Help the first person to know ifthe numbers set entered by the second person includes the two numbers he is looking for!InputThe first person shall enter two numbers. The second person enters set of numbers of any size. S/hecan enter any range of numbers (up to you how to read those numbers).OutputMessage showing if both numbers entered by the first person have been found or not. If one of thenumbers was found show which one has been found. Hint: you may need to use flag-controlled loop.arrow_forwardWrite aprogram in C++ that takes input the number 203212 and prints the number in reverse order. Built-in functions are not allowed. input : 203212arrow_forward
- Pls make a code for this on c++ and make sure it is 100% correct. i wastred 4 questoins on this and they all are not correct. Write the code as described in the questions below. Submit your code electronically in the box at the bottom. You may only use Java, C# or C++. The economy is defined using a 2-dimensional data structure: A “payday” will be considered to be any region of $ values where all cells in the region are connected either vertically or horizontally. For example, the following illustrates a matrix with 5 rows and 8 columns containing three objects. $’s and P are used in the diagram to represent the two types of values: PPPP$PPPPPP$$PPPPP$$PPP$PP$PPPP$P$PPP$$$ a) Write a program to read in the data from the text file and store it into a data structure. Your program should output it to the screen after it has read in the file. (If you can’t get this to work hard-code the above example and continue to part b). Here is a sample text file (containing the above data):…arrow_forwardPlease i need solution for these in c++ languagearrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY