Write a Python program that will process the text file, Gettysburg.txt, by calculating the total words and output the number of occurrences of each word in the file.
The program needs to open the file and process each line. You need to add each word to the dictionary with a frequency of 1 or update the word’s count by 1. You need to print the output from high to low frequency.
The program needs 4 functions.
The first function is called add_word where you add each word to the dictionary. The parameters are the word and a dictionary. There is no return value.
The second function is called Process_line where you strip off various characters, split out the words, and so on. The parameters are a line and a dictionary. It calls the add_word function with each processed word. There is no return value.
The third function is called Pretty_print where this will be the printing function. The parameter is a dictionary. There is no return value.
The fourth function is the main where it will open the file and call Process_line on each line. When finished, it will call the Pretty_print function to print the dictionary.
Gettysburg.txt
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.
Abraham Lincoln
November 19, 1863
In: Computer Science
Carefully Read the Case study and answer both questions in 250 words each.
Shades of meaning
If you have tried the activities in the previous parts, you are likely to be appreciating afresh just how much is going on around our words as we use them to communicate.
As poet T.S. Eliot says, “Words... slip, slide, perish, Decay with imprecision, will not stay in place, Will not stay still.” Surely, our words have made it possible for us to construct our knowledge. But what meanings do they attempt to fix in place, and what meanings are they given by the millions of others who might read and interpret them? Our languages are, beyond doubt, an amazing way of knowing in enabling us to share knowledge. But how do we manage such sharing with words that ‘decay with imprecision’?
We do make various attempts to pin down and hold in place the core meanings of our words, prime among them being the move we take to define our terms. If we want to make sure that we are all talking about the same thing when we exchange ideas, we check our basic understanding. Many a discussion has reached a frustrating conclusion because the speakers never did figure out that they were entering with different understandings of a core concept, a central word. Witness social debates on ‘poverty’ and ‘development’ – let alone ‘the economy’ or ‘freedom’ or ‘war’. When a simple word such as ‘rock’ can slide around as we operate with it, what slippery territory we enter when we want to talk about the larger concepts that shape our understanding of the world!
When we define our terms, we are trying to use the symbols of our language to make another specific symbol precise. Definitions are statements within the system of symbols, rather like moves in a large language game, with each piece depending upon the others. We call the core definitional meaning the ‘denotation’ of the word, or in cases of multiple core meanings (‘rock’ is a noun or a verb, with unlike meanings), the ‘denotations’.
We call the overtones of meaning, the nuances that arise as we use the word in particular contexts, its ‘connotations’. It is the connotations of a word that give it its ‘flavour’ or its ‘halo’ of meaning.
How we deal with the ambiguity of language – its imprecision in meaning and its connotations – depends on what the nature of our communication is and the kind of knowledge we are exchanging.
In some fields, precision is crucial. The sciences take care to define terms tightly in order to use exactly the right word, or leave language behind and instead opt in favour of using numbers or other sets of symbols. In other fields, finding exactly the right word may depend on deliberately using the ambiguity. Diplomacy and negotiation, for example, sometimes depend on indirection and subtle suggestion, and literature often depends for its expressive power on language whose connotations stir subjective associations of meaning. In yet other areas of our lives, we may not even care much about what the words we are using actually mean, since the communication of friendly chat is carried largely by the tone and accompanying body movement, and simply by the fact that we are making mouth noise companionably together. Altogether, the kind of knowledge we want to communicate affects our expectations of language and the ways we use it.
The Dictionary
1 What is the role of a dictionary? Is it descriptive, recording the changes in language as they happen? Or is it prescriptive, legislating what changes in language are acceptable?
2 In language, new words and usages are generated almost constantly, in response to changing need and creative impulse. Why do you think that some languages (French, Spanish, Icelandic) have official institutes which regulate what new ones are accepted? What are the arguments for and against preserving a language in a particular form?
In: Operations Management
Hello, I need to divide my code in this different parts.
Use a standard approach to source files in this assignment: a .cpp for each function (you have at least two – main and ageCalc) a header file for the student struct, properly guarded
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
#define nullptr NULL
#define MAX_SIZE 100
struct Student
{
string firstName;
char middleName;
string lastName;
char collegeCode;
int locCode;
int seqCode;
int age;
};
struct sort_by_age
{
inline bool operator()(const Student *s1, const Student *s2)
{
return (s1->age < s2->age);
}
};
int ageCalc(Student *studs[], Student *&youngest);
int main()
{
Student *students[MAX_SIZE] = {nullptr};
ifstream Myfile;
Myfile.open("a2data.txt");
if (!Myfile.is_open())
{
cout << "Could not open the file!";
return 1;
}
vector<string> words;
string line;
while (!Myfile.eof())
{
getline(Myfile, line);
line.c_str();
int i = 0;
string word = "";
while (line[i] != '\0')
{
if (line[i] != ' ')
{
word = word + line[i];
i++;
}
else
{
if (word != "")
words.push_back(word);
word = "";
i++;
}
}
words.push_back(word);
}
Myfile.close();
int count = 0;
string fname = words.at(count);
count++;
int n = 0;
while (count < words.size() - 2)
{
Student *s = new Student;
s->firstName = fname;
string mname = words.at(count);
s->middleName = mname[0];
count++;
s->lastName = words.at(count);
if (words.at(count).size() >= 12)
{
if (words.at(count)[1] >= '0' && words.at(count)[1] <= '9')
{
count--;
s->middleName = ' ';
s->lastName = words.at(count);
}
}
count++;
string id = words.at(count);
count++;
s->collegeCode = id[0];
string loc = "";
loc = loc + id[1];
loc = loc + id[2];
s->locCode = stoi(loc);
string seq = "";
for (int j = 3; j < 9; j++)
{
seq = seq + id[j];
}
s->seqCode = stoi(seq);
string age = "";
age = age + id[9];
age = age + id[10];
age = age + id[11];
s->age = stoi(age);
fname = id.erase(0, 12);
students[n] = s;
n++;
}
words.clear();
sort(students, students + n, sort_by_age());
cout << setw(15) << left << "Last Name";
cout << setw(15) << left << "Midlle Name";
cout << setw(15) << left << "First Name";
cout << setw(15) << left << "College Code";
cout << setw(12) << left << "Location";
cout << setw(12) << left << "Sequence";
cout << setw(12) << left << "Age" << endl;
cout << "=======================================================================================" << endl;
for (int i = 0; i < n; i++)
{
cout << setw(15) << left << students[i]->lastName;
cout << setw(15) << left << students[i]->middleName;
cout << setw(20) << left << students[i]->firstName;
cout << setw(13) << left << students[i]->collegeCode;
cout << setw(10) << left << students[i]->locCode;
cout << setw(12) << left << students[i]->seqCode;
cout << students[i]->age << endl;
}
cout << endl;
Student *youngest = NULL;
int avg_age = ageCalc(students, youngest);
cout << "Average age is: " << avg_age << endl;
cout << "Youngest student is " << youngest->firstName << " " << youngest->middleName << " " << youngest->lastName << endl;
return 0;
}
int ageCalc(Student *studs[], Student *&youngest)
{
youngest = studs[0];
int i = 0;
int avg_age = 0;
while (studs[i] != NULL)
{
avg_age += studs[i]->age;
if (youngest->age > studs[i]->age)
youngest = studs[i];
i++;
}
return avg_age / i;
}
File needed:
https://drive.google.com/file/d/15_CxuGnFdnyIj6zhSC11oSgKEYrosHck/view?usp=sharing
In: Computer Science
Hello, I need to divide my code in this different parts.
Use a standard approach to source files in this assignment: a .cpp for each function (you have at least two – main and ageCalc) a header file for the student struct, properly guarded
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
#define nullptr NULL
#define MAX_SIZE 100
struct Student
{
string firstName;
char middleName;
string lastName;
char collegeCode;
int locCode;
int seqCode;
int age;
};
struct sort_by_age
{
inline bool operator()(const Student *s1, const Student *s2)
{
return (s1->age < s2->age);
}
};
int ageCalc(Student *studs[], Student *&youngest);
int main()
{
Student *students[MAX_SIZE] = {nullptr};
ifstream Myfile;
Myfile.open("a2data.txt");
if (!Myfile.is_open())
{
cout << "Could not open the file!";
return 1;
}
vector<string> words;
string line;
while (!Myfile.eof())
{
getline(Myfile, line);
line.c_str();
int i = 0;
string word = "";
while (line[i] != '\0')
{
if (line[i] != ' ')
{
word = word + line[i];
i++;
}
else
{
if (word != "")
words.push_back(word);
word = "";
i++;
}
}
words.push_back(word);
}
Myfile.close();
int count = 0;
string fname = words.at(count);
count++;
int n = 0;
while (count < words.size() - 2)
{
Student *s = new Student;
s->firstName = fname;
string mname = words.at(count);
s->middleName = mname[0];
count++;
s->lastName = words.at(count);
if (words.at(count).size() >= 12)
{
if (words.at(count)[1] >= '0' && words.at(count)[1] <= '9')
{
count--;
s->middleName = ' ';
s->lastName = words.at(count);
}
}
count++;
string id = words.at(count);
count++;
s->collegeCode = id[0];
string loc = "";
loc = loc + id[1];
loc = loc + id[2];
s->locCode = stoi(loc);
string seq = "";
for (int j = 3; j < 9; j++)
{
seq = seq + id[j];
}
s->seqCode = stoi(seq);
string age = "";
age = age + id[9];
age = age + id[10];
age = age + id[11];
s->age = stoi(age);
fname = id.erase(0, 12);
students[n] = s;
n++;
}
words.clear();
sort(students, students + n, sort_by_age());
cout << setw(15) << left << "Last Name";
cout << setw(15) << left << "Midlle Name";
cout << setw(15) << left << "First Name";
cout << setw(15) << left << "College Code";
cout << setw(12) << left << "Location";
cout << setw(12) << left << "Sequence";
cout << setw(12) << left << "Age" << endl;
cout << "=======================================================================================" << endl;
for (int i = 0; i < n; i++)
{
cout << setw(15) << left << students[i]->lastName;
cout << setw(15) << left << students[i]->middleName;
cout << setw(20) << left << students[i]->firstName;
cout << setw(13) << left << students[i]->collegeCode;
cout << setw(10) << left << students[i]->locCode;
cout << setw(12) << left << students[i]->seqCode;
cout << students[i]->age << endl;
}
cout << endl;
Student *youngest = NULL;
int avg_age = ageCalc(students, youngest);
cout << "Average age is: " << avg_age << endl;
cout << "Youngest student is " << youngest->firstName << " " << youngest->middleName << " " << youngest->lastName << endl;
return 0;
}
int ageCalc(Student *studs[], Student *&youngest)
{
youngest = studs[0];
int i = 0;
int avg_age = 0;
while (studs[i] != NULL)
{
avg_age += studs[i]->age;
if (youngest->age > studs[i]->age)
youngest = studs[i];
i++;
}
return avg_age / i;
}
File needed:
https://drive.google.com/file/d/15_CxuGnFdnyIj6zhSC11oSgKEYrosHck/view?usp=sharing
In: Computer Science
Hello, I need to divide my code in this different parts.
Use a standard approach to source files in this assignment: a .cpp for each function (you have at least two – main and ageCalc) a header file for the student struct, properly guarded
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
#define nullptr NULL
#define MAX_SIZE 100
struct Student
{
string firstName;
char middleName;
string lastName;
char collegeCode;
int locCode;
int seqCode;
int age;
};
struct sort_by_age
{
inline bool operator()(const Student *s1, const Student *s2)
{
return (s1->age < s2->age);
}
};
int ageCalc(Student *studs[], Student *&youngest);
int main()
{
Student *students[MAX_SIZE] = {nullptr};
ifstream Myfile;
Myfile.open("a2data.txt");
if (!Myfile.is_open())
{
cout << "Could not open the file!";
return 1;
}
vector<string> words;
string line;
while (!Myfile.eof())
{
getline(Myfile, line);
line.c_str();
int i = 0;
string word = "";
while (line[i] != '\0')
{
if (line[i] != ' ')
{
word = word + line[i];
i++;
}
else
{
if (word != "")
words.push_back(word);
word = "";
i++;
}
}
words.push_back(word);
}
Myfile.close();
int count = 0;
string fname = words.at(count);
count++;
int n = 0;
while (count < words.size() - 2)
{
Student *s = new Student;
s->firstName = fname;
string mname = words.at(count);
s->middleName = mname[0];
count++;
s->lastName = words.at(count);
if (words.at(count).size() >= 12)
{
if (words.at(count)[1] >= '0' && words.at(count)[1] <= '9')
{
count--;
s->middleName = ' ';
s->lastName = words.at(count);
}
}
count++;
string id = words.at(count);
count++;
s->collegeCode = id[0];
string loc = "";
loc = loc + id[1];
loc = loc + id[2];
s->locCode = stoi(loc);
string seq = "";
for (int j = 3; j < 9; j++)
{
seq = seq + id[j];
}
s->seqCode = stoi(seq);
string age = "";
age = age + id[9];
age = age + id[10];
age = age + id[11];
s->age = stoi(age);
fname = id.erase(0, 12);
students[n] = s;
n++;
}
words.clear();
sort(students, students + n, sort_by_age());
cout << setw(15) << left << "Last Name";
cout << setw(15) << left << "Midlle Name";
cout << setw(15) << left << "First Name";
cout << setw(15) << left << "College Code";
cout << setw(12) << left << "Location";
cout << setw(12) << left << "Sequence";
cout << setw(12) << left << "Age" << endl;
cout << "=======================================================================================" << endl;
for (int i = 0; i < n; i++)
{
cout << setw(15) << left << students[i]->lastName;
cout << setw(15) << left << students[i]->middleName;
cout << setw(20) << left << students[i]->firstName;
cout << setw(13) << left << students[i]->collegeCode;
cout << setw(10) << left << students[i]->locCode;
cout << setw(12) << left << students[i]->seqCode;
cout << students[i]->age << endl;
}
cout << endl;
Student *youngest = NULL;
int avg_age = ageCalc(students, youngest);
cout << "Average age is: " << avg_age << endl;
cout << "Youngest student is " << youngest->firstName << " " << youngest->middleName << " " << youngest->lastName << endl;
return 0;
}
int ageCalc(Student *studs[], Student *&youngest)
{
youngest = studs[0];
int i = 0;
int avg_age = 0;
while (studs[i] != NULL)
{
avg_age += studs[i]->age;
if (youngest->age > studs[i]->age)
youngest = studs[i];
i++;
}
return avg_age / i;
}
File needed:
https://drive.google.com/file/d/15_CxuGnFdnyIj6zhSC11oSgKEYrosHck/view?usp=sharing
In: Computer Science
Hello, I need to divide my code in this different parts.
Use a standard approach to source files in this assignment: a .cpp for each function (you have at least two – main and ageCalc) a header file for the student struct, properly guarded
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
#define nullptr NULL
#define MAX_SIZE 100
struct Student
{
string firstName;
char middleName;
string lastName;
char collegeCode;
int locCode;
int seqCode;
int age;
};
struct sort_by_age
{
inline bool operator()(const Student *s1, const Student *s2)
{
return (s1->age < s2->age);
}
};
int ageCalc(Student *studs[], Student *&youngest);
int main()
{
Student *students[MAX_SIZE] = {nullptr};
ifstream Myfile;
Myfile.open("a2data.txt");
if (!Myfile.is_open())
{
cout << "Could not open the file!";
return 1;
}
vector<string> words;
string line;
while (!Myfile.eof())
{
getline(Myfile, line);
line.c_str();
int i = 0;
string word = "";
while (line[i] != '\0')
{
if (line[i] != ' ')
{
word = word + line[i];
i++;
}
else
{
if (word != "")
words.push_back(word);
word = "";
i++;
}
}
words.push_back(word);
}
Myfile.close();
int count = 0;
string fname = words.at(count);
count++;
int n = 0;
while (count < words.size() - 2)
{
Student *s = new Student;
s->firstName = fname;
string mname = words.at(count);
s->middleName = mname[0];
count++;
s->lastName = words.at(count);
if (words.at(count).size() >= 12)
{
if (words.at(count)[1] >= '0' && words.at(count)[1] <= '9')
{
count--;
s->middleName = ' ';
s->lastName = words.at(count);
}
}
count++;
string id = words.at(count);
count++;
s->collegeCode = id[0];
string loc = "";
loc = loc + id[1];
loc = loc + id[2];
s->locCode = stoi(loc);
string seq = "";
for (int j = 3; j < 9; j++)
{
seq = seq + id[j];
}
s->seqCode = stoi(seq);
string age = "";
age = age + id[9];
age = age + id[10];
age = age + id[11];
s->age = stoi(age);
fname = id.erase(0, 12);
students[n] = s;
n++;
}
words.clear();
sort(students, students + n, sort_by_age());
cout << setw(15) << left << "Last Name";
cout << setw(15) << left << "Midlle Name";
cout << setw(15) << left << "First Name";
cout << setw(15) << left << "College Code";
cout << setw(12) << left << "Location";
cout << setw(12) << left << "Sequence";
cout << setw(12) << left << "Age" << endl;
cout << "=======================================================================================" << endl;
for (int i = 0; i < n; i++)
{
cout << setw(15) << left << students[i]->lastName;
cout << setw(15) << left << students[i]->middleName;
cout << setw(20) << left << students[i]->firstName;
cout << setw(13) << left << students[i]->collegeCode;
cout << setw(10) << left << students[i]->locCode;
cout << setw(12) << left << students[i]->seqCode;
cout << students[i]->age << endl;
}
cout << endl;
Student *youngest = NULL;
int avg_age = ageCalc(students, youngest);
cout << "Average age is: " << avg_age << endl;
cout << "Youngest student is " << youngest->firstName << " " << youngest->middleName << " " << youngest->lastName << endl;
return 0;
}
int ageCalc(Student *studs[], Student *&youngest)
{
youngest = studs[0];
int i = 0;
int avg_age = 0;
while (studs[i] != NULL)
{
avg_age += studs[i]->age;
if (youngest->age > studs[i]->age)
youngest = studs[i];
i++;
}
return avg_age / i;
}
File needed:
https://drive.google.com/file/d/15_CxuGnFdnyIj6zhSC11oSgKEYrosHck/view?usp=sharing
In: Computer Science
QUESTION 1
How many sounds are in the name "James"? (Count each occurrence of a given sound separately, e.g., in "bluebird" [blubɹ̩d], there would be 6 sounds -- you would count [b] twice).
|
3 |
||
|
4 |
||
|
5 |
||
|
6 |
0.125 points
QUESTION 2
How many sounds are in the word "axis"? (Count each occurrence of a given sound separately, e.g., in "bluebird" [blubɹ̩d], there would be 6 sounds -- you would count [b] twice).
|
3 |
||
|
4 |
||
|
5 |
||
|
6 |
0.125 points
QUESTION 3
Which of the following is a mid central unrounded lax vowel?
|
[ɛ] |
||
|
[æ] |
||
|
[ɑ] |
||
|
[ʌ] |
||
|
[ʊ] |
0.125 points
QUESTION 4
[b] vs [k]
these two phones are different in:
(Select all that apply)
|
Manner |
||
|
Voicing |
||
|
Place |
0.125 points
QUESTION 5
[u] vs [ʌ]
these two phones are different in:
(Select all that apply)
|
Tongue Height |
||
|
Tongue advancement |
||
|
Roundedness |
||
|
Tenseness |
0.125 points
QUESTION 6
[v] vs [t]
these two phones are different in:
(Select all that apply)
|
Voicing |
||
|
Manner |
||
|
Place |
0.125 points
QUESTION 7
[æ] vs [ɑ]
these two phones are different in:
(Select all that apply)
Select one or more:
|
Tongue Height |
||
|
Tongue advancement |
||
|
Roundedness |
||
|
Tenseness |
0.125 points
QUESTION 8
[ɛ] vs [æ]
these two phones are different in:
(Select all that apply)
Select one or more:
|
Tongue Height |
||
|
Tongue Advancement |
||
|
Roundedness |
||
|
Tenseness |
0.125 points
QUESTION 9
[ʃ] vs [v]
these two phones are different in:
(Select all that apply)
|
Place |
||
|
Manner |
||
|
Voicing |
0.125 points
QUESTION 10
[ʤ] vs [ɡ]
these two phones are different in:
(Select all that apply)
|
Manner |
||
|
Voicing |
||
|
Place |
0.125 points
QUESTION 11
[ʧ] vs [ʤ]
these two phones are different in:
(Select all that apply)
|
Place |
||
|
Manner |
||
|
Voicing |
0.125 points
QUESTION 12
Write the English word corresponding to the following IPA
transcription
[ bjuɾi ]
0.125 points
QUESTION 13
How many sounds are in the word "towed"? (Count each occurrence of a given sound separately, e.g., in "bluebird" [blubɹ̩d], there would be 6 sounds -- you would count [b] twice).
|
3 |
||
|
4 |
||
|
5 |
||
|
6 |
0.125 points
QUESTION 14
Write the English word corresponding to the following IPA
transcription
[ imoʊʃən ]
0.125 points
QUESTION 15
Type in the IPA symbol for a mid back rounded lax
vowel.
Type only a single lowercase character; do not use brackets or
extra spaces.
0.125 points
QUESTION 16
Type in the IPA symbol for a voiced bilabial
glide.
Type only a single lowercase character; do not use brackets or
extra spaces.
0.125 points
QUESTION 17
Type in the IPA symbol for a voiceless velar
stop.
Type only a single lowercase character; do not use brackets or
extra spaces.
0.125 points
QUESTION 18
Type in the IPA symbol for a voiceless glottal
stop.
Type only a single lowercase character; do not use brackets or
extra spaces.
0.125 points
QUESTION 19
Write the English word corresponding to the following IPA
transcription
[ kwɑɪjətli ]
0.125 points
QUESTION 20
Write the English word corresponding to the following IPA
transcription
[ ɹɑɪd ]
0.125 points
QUESTION 21
Write the English word corresponding to the following IPA
transcription
[ ðoʊ ]
0.125 points
QUESTION 22
What is the IPA symbol for a voiced alveolar flap?
|
[ ɹ ] |
||
|
[ ɾ ] |
||
|
[ d ] |
||
|
[ t ] |
||
|
[ ʔ ] |
0.125 points
QUESTION 23
Which of the following is a voiced postalveolar affricate?
|
[ʤ] |
||
|
[s] |
||
|
[z] |
||
|
[ʧ] |
||
|
[ʒ] |
0.125 points
QUESTION 24
What is the IPA symbol for a voiced velar nasal?
|
[n] |
||
|
[ŋ] |
||
|
[m] |
||
|
[g] |
||
|
[k] |
In: Psychology
1. What is the purpose of the International Monetary Fund? and the Word Bank? Provide some explanation of their practices.
2. What are the 5 levels of regional trade agreements? How do they differ from each other?
3- What are the public goods provided by international institutions?
In: Economics
GIVE A DEFINITION. PLEASE BE CLEAR OF WHICH YOU ARE DEFINING BY WRITING THE WORD NEXT TO THE DEFINITION
In: Statistics and Probability
In: Finance