Ranking Programming Languages Suppose you are given an input file with the names
ID: 3705618 • Letter: R
Question
Ranking Programming Languages Suppose you are given an input file with the names of few top ranked programming languages and names are separated by comma. Your task is to read the names from the input file and print the names in an output file and give them the rank in the order they appear. So, the first language gets the rank of 1, the next one gets the rank 2 and so orn. Lab ScenarIO: 1. languages is in one line separated by comma. The format of the file is as follows: 2. You will perform the file open operation. And then perform the read operation with your 3. Once you are done reading, process the file content and then using your favorite write The program reads from an already provided input file: ILA8.in. The name of the PYTHON, SQL,LAVA, JAVASCRIPT, C#, C++, PHP, PERL, RUBY/RAILS favorite read functions and read the content of the file. operations and write the content to another file. Please don't forget to close the file. So that "Python" gets the rank of 1, "SQL" will be rank 2 and so on. The sample output should look like this: Language Rank PYTHON SQL 2 JAVA3 JAVASCRIPT 4 C# 5 C++ 6 PHP7 PERL 8 RUBY/RAILS 9 For this lab, you are expected to use functions and file VO operations. There should be at least 3 user defined functions. One main), one file_readO to read the content of the file ILA8.in and one for file_write0 to write the table to another file. The output file should be named as: firstname_lastname ILA8.out 4.Explanation / Answer
As you didn't mentioned any language, I did it in c++.
list.cpp
===============
#include<iostream>
#include<string>
#include<fstream>
#include <sstream>
using namespace std;
//function for reading the file & sending the cntent to main
string file_read()
{
string content;
ifstream file("ILA8.in");
if(file.is_open())
{
file>>content;
}
return content;
}
//function for writing into output file
void file_write(string content)
{
istringstream s(content);
string token;
int rank = 1;
ofstream file("yourname_ILA8.out");
if(file.is_open())
{
file<<"Language Rank ";
while(getline(s, token, ','))
{
file<<token<<" "<<rank<<" ";
rank = rank+1;
}
}
}
//main function
int main()
{
string s = file_read();
file_write(s);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.