Question

Write a C++ code to make a simple program that imports the input file in and gets the results as specified

Please follow the instructions and paste the code below as the answer with a screenshot of the output to prove it worked.

Input file -> https://www.dropbox.com/s/444jofkchu6ylwr/names.txt?dl=0

Scoring Names You will be using the provided names.txt file, text file containing over five-thousand first names, and you will calculate a score for each name. Begin by reading the names from the file and sorting them in alphabetical order. Then, you will compute an alphabetical value for each name where A is 1, Bis 2, C is 3 and so on. The alphabetical value of a name is just the sum of the values of the letters in the name. To compute the name-score for a name, you simply multiply this alphabetical value by its position in the sorted list. For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 15 12 9 14 53, is the 938th name in the list. So, the name-score for COLIN would be 938 53 49714. What is the sum total of all the name-scores in the file?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Notes:The name.txt given in the link could not be opened. So I create a test file that has 1000 names.So my program is based on 1000 names.U can change it to 5000 just by changing #define MAX 1000 to %define MAX 5000

------------------------------------------------------------------------------------------------------------------------------------------------------------

/* C++ program to read first names of 1000 peoples.store them in a
a file in alphabetical order . Then calculate name score of each name
and then calculate the total namescore of each employee*/
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
#define MAX 1000
//using namespace std;

//Structure defination
struct NameInfo
   {
   int sl;
   char name[25];
   unsigned long int namescore;
   };
//main program
int main()
   {
   ifstream fin;
   struct NameInfo namelist[MAX];
   char temp[25];
   //open the file containing the first names
   fin.open("names.txt",ios::in);

   if(fin.fail())
       {
       cout<<"unable to open the file!";
       exit(0);
       }
   int i=0,j,n;
   // read from file and store in the namelist
   while(!fin.eof())
       {
       namelist[i].sl=i+1;
       fin>>namelist[i].name;
       namelist[i].namescore=0;
       i++;
       }
   n=i;
   //Sort in alphabetical order
   for(j=1;j<n;j++)
       {
       strcpy(temp,namelist[j].name);
       i=j-1;
       while (i>=0 && strcmp(temp,namelist[i].name)<0)
           {
           strcpy(namelist[i+1].name,namelist[i].name);
           i--;
           }
       strcpy(namelist[i+1].name,temp);
       }
   //compute the namescore of each person
   char x;
   for(i=0;i<n;i++)
       {
       unsigned long int alphavalue=0;
       for(j=0;namelist[i].name[j]!='\0';j++)
           {
           x=toupper(namelist[i].name[j]);
           alphavalue+=(x-64);
           }
       namelist[i].namescore=namelist[i].sl*alphavalue;
       }

   //Compute the total name score of all persons
   unsigned long int totalnamescore=0;
   for(i=0;i<n;i++)
       {
       totalnamescore+= namelist[i].namescore;
       }

   //Print the names with namescore
   for(i=0;i<n;i++)
       {
       cout<<endl<<namelist[i].sl<<" "<<namelist[i].name<<" "<<namelist[i].namescore;
       }

   //print total name score
   cout<<endl<<"Total name score ="<<totalnamescore;
   return 0;
   }

//------------------------------------------------

output: o/p consist of 100 names so could send all . snap shot of the last page is below

E DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program: 77 WALTER 77183 78 WNANDA 42054 79 WARREN 77341 80 WAYNE 666

Add a comment
Know the answer?
Add Answer to:
Write a C++ code to make a simple program that imports the input file in and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ANSWER USING JAVA CODE (1)The sum of the squares of the first ten natural numbers is,...

    ANSWER USING JAVA CODE (1)The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640. Find the difference between the...

  • Python program - Write a Python program, in a file called sortList.py, which, given a list...

    Python program - Write a Python program, in a file called sortList.py, which, given a list of names, sorts the names into alphabetical order. Use a one dimensional array to hold the list of names. To do the sorting use a simple sorting algorithm that repeatedly takes an element from the unsorted list and puts it in alphabetical order within the same list. Initially the entire list is unsorted. As each element is placed in alphabetical order, the elements in...

  • c++ The program will be recieved from the user as input name of an input file...

    c++ The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to search for, when it find...

  • 1. Write a program to input a list of names (strings) from the user and store...

    1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or by entering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description:...

    Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description: For this project you will write a program to: a) read-in the 10 first names from a file (the file is a priori given to have exactly 10 entries, of a maximum length of 8 letters each) into a 2-dimensional character array, b) output the names to the terminal with each one preceded by a number indicating its original order in the list, c)...

  • Write a Python program to read lines of text from a file. For each word (i.e,...

    Write a Python program to read lines of text from a file. For each word (i.e, a group of characters separated by one or more whitespace characters), keep track of how many times that word appears in the file. In the end, print out the top twenty counts and the corresponding words for each count. Print each value and the corresponding words, in alphabetical order, on one line. Print this in reverse sorted order by word count. You can assume...

  • Task 1: Write a Python program that takes as input from the user the name of a file containing po...

    python code: Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored...

  • c++ Instructions Overview In this programming challenge you will create a program to handle student test...

    c++ Instructions Overview In this programming challenge you will create a program to handle student test scores.  You will have three tasks to complete in this challenge. Instructions Task 1 Write a program that allocates an array large enough to hold 5 student test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the...

  • PLEASE UPLOAD or Write a simple PSEUDO CODE AND JAVA CODE for this program WITH COMMENTS...

    PLEASE UPLOAD or Write a simple PSEUDO CODE AND JAVA CODE for this program WITH COMMENTS IN BOTH TELLING WHAT EACH PART DOES. (I NEED BOTH CODES NOT JUST ONE OR THE OTHER) Problem Statement A golf club has a small tournament consisting of five golfers every weekend. The club president has asked you to design a program that does the following: Reads player’s names and their scores from the keyboard for each of the five golfers and simulates writing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT