So far this is what I have:
#include <iomanip>
#include <cmath>
#include <fstream>
#include<string>
#include<iostream>
using namespace std;
int main()
{
ifstream infile;
ofstream outfile;
infile.open ("Wordcalc.txt");
outfile.open ("WOutput");
char A = (1*2.0);//value for letter A
char C = (3 - 20.4);
char D = ((4/12.0) *3.09);
char E = ((5/3.0)+5.0);
char L = ((12+17)*3.7/2.8)+3.17;
char N = (14 /4.2-6.12)*8.4;
char R = (18.0/2);
char S = ((19*3.0) + 7.0)/2.1;
char T = (20+10.18);
string names;
double wordlength = 0;
double wordeval = 0;
double value = 0;
while (infile>>names)
{
cout<<"Words"<<setw(15)<<"Value"<<endl;
cout<<names<<setw(15)<<value<<endl;
cout<<"The average word length is : "<<wordlength<<endl;
cout<<"The average word evaluation is : "<<wordeval<<endl;
}
infile.close();
outfile.close();
return 0;
}
The assignment:
This program, which must use functions and parameter passing, reads in a list of single
words from a sequential file called "a:\wordcalc.txt". It calculates a word value based upon
formulae for individual selected letters in the word (explained below). The program displays
each word along with its calculated word value. lt then displays a count of the total words,
the average word length and the average word evaluation.
The letter evaluations are based upon the ORDINAL position ofthe CAPITAL letter in the
alphabet (examples: A = 1; B = 2; C = 3; Y = 25; Z = 26). The following are the formulae for
(all other letters have a value of zero):
A ==>ordinal value * 2.0
C ==>ordinal value - 20.4
D ==>ordinal value l 12.0 * 3.09
E ==>ordinal value l 3.0 + 5.0
L ==>((ordinal value + 17.0)* 3.7/2.8)+ 3.17
N ==>(ordinaI value /4.2 - 6.12)* 8.4
R ==>ordinal value /2.0
S ==>((ordinaI value * 3.0)+ 7.0)/2.1
T ==>ordinal value +10.18
Example the word COTTON evaluates as follows
C ==> -17.4
O ==> 0.0
Example: The evaluation of the word COTTON:
C=-17.4
O=0.0
T=30.18
T=30.18
O=0.0
N=-23.408
Evaluation is 19.552
* A switch may may not be used to determine the ordinal value of the letter, but is necessary for the individual letter calcualtion.
Suggested functions:
1 for reading
1 for evaluating
1 for displaying the count
1 for calcualting and displaying the word length average
1 for displaying the word evaluation
* There will not be more than 60 words in the infile.
A few questions:
1. Is my declaration of each letter correct?
2. How do i get the program to evaluation each individual letter value and then move on to the other letter in the same phrase and then unto the next phrase in the infile?
3. How do i store the value and the length of each phrase, so as to calculate the average at the end?
4. What can i use to allow the program to continue even if the letter is in lower case?
All assitance is appreciated.