Hi. I am trying to improve my grades before the end of the semester. Can someone
ID: 3825377 • Letter: H
Question
Hi. I am trying to improve my grades before the end of the semester. Can someone assist me with this program? I am writing in C++ language. Thank you so much.
You have a set of different types of robots that combine to generate poetry. All robots have a common vocabulary and have a unique color that identifies them (red, blue, purple, green, yellow, orange). The kind of words in the vocabulary that each robot understands depends on the type of the robot. Each robot produces phrases that are randomly generated on command using a vocabulary that consists of nouns, verbs, adverbs, adjectives, articles, and prepositions. The types of phrases that each robot can produce are: o The red robots produce a phrase consisting of 1 adjective followed by 1 noun i.e., "happy campers') The blue robots produce a phrase consisting of 1 verb followed by 1 adverb i.e., eating rapidly The purple robots produce a phrase consisting of 1 preposition, 1 article, 1 adjective, and 1 noun ("under the fiery rock') o The green robots produce a phrase consisting of 1 article, 1 adjective, 1 noun, and 1 verb (i.e., "the happy sun burns' o The yellow robots produce a phrase consisting of 2 nouns joined by "and' 1.c cow and chicken') o The orange robots produce a phrase consisting of 2 verbs joined by "or" i.e., "bending or calling") You have six data files, one for each type of word (nouns.txt, verbs.txt, adverbs.txt, adjectives.txt, articles txt and prepositions txt DAPrograms C++ PoetryDebug Poetry.exe beautiful tourist Your program will combine these phrases into awfully meeting poems. There are four set modes: over our motionless freezer red, blue, purple which early nest hearing hand and wrist green, yellow, purple, orange around its vivacious captain green, yellow, red, blue, orange, purple upsetting or shrinking any 4 randomly selected robots hine dead oracle forbidding bear and wikipedian obedient nightingale The output at the right shows the poems legally washing ore telling or nuzzling produced for each of these modes. amid his defiant pheasant Note that you have a chance for extra credit your narrow bed singing awlessly attacking by adding a loop and a user menu to select the until an curly intern at his jolly pheasant poem type.Explanation / Answer
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
struct StudentData
{
int studentID;
string first_name;
string last_name;
int exam1;
int exam2;
int exam3;
int total;
char ch;
};
const int SIZE = 7;
const int INFO =3;
void openInputFile(ifstream &, string);
void getTotal(StudentData[]);
void getGrade(StudentData[]);
void calcLowest(StudentData[], int &, int &, int &, int &, int[]);
void calcHighest(StudentData[], int &, int &, int &, int &, int[]);
void getAverage(StudentData[], int, double &, double &, double &, double &, double[]);
void getStd(StudentData[], double &, double &, double &, double &, double &, double &, double &, double &, double[]);
void print(StudentData[], int[], int[], double[], double[]);
void sort(StudentData[]);
int main()
{
StudentData arr[SIZE];
int lowest1, lowest2, lowest3;
int highest1, highest2, highest3;
double average1 = 0, average2 = 0, average3 = 0;
double std1 = 0, std2 = 0, std3 = 0;
int lowest[INFO] = {};
int highest[INFO] = {};
double average[INFO] = {};
double standardDeviation[INFO] = {};
ifstream inFile;
string inFileName = "C:\Users\Lisa\Desktop\scores.txt";
openInputFile(inFile, inFileName);
for(int count = 0; count < SIZE; count++)
{
inFile >> arr[count].studentID >> arr[count].first_name >> arr[count].last_name >> arr[count].exam1 >> arr[count].exam2 >> arr[count].exam3;
}
inFile.close();
getTotal(arr);
getGrade(arr);
calcLowest(arr, lowest1, lowest2, lowest3, lowest4, lowest);
calcHighest(arr, highest1, highest2, highest3, highest4, highest);
getAverage(arr, SIZE, average1, average2, average3, average);
getStd(arr, std1, std2, std3,average1, average2, average3,standardDeviation);
cout << " ";
print(arr, lowest, highest, average, standardDeviation);
cout << " ";
sort(arr);
print(arr, lowest, highest, average, standardDeviation);
system("PAUSE");
return 0;
}
void openInputFile(ifstream &inFile, string inFileName)
{
inFile.open(inFileName);
if (!inFile)
{
cout << "Error to open file." << endl;
cout << endl;
return;
}
}
void getTotal(StudentData arr[])
{
for(int i = 0; i < SIZE; i++)
{
arr[i].total = arr[i].exam1 + arr[i].exam2 + arr[i].exam3;
}
}
void getGrade(StudentData arr[])
{
for(int i = 0; i < SIZE; i++)
{
if(arr[i].total >= 270)
arr[i].ch = 'A';
else if(arr[i].total >= 240)
arr[i].ch = 'B';
else if(arr[i].total >= 210)
arr[i].ch = 'C';
else if(arr[i].total >= 180)
arr[i].ch = 'D';
else
arr[i].ch = 'F';
}
}
void calcLowest(StudentData arr[], int &lowest1, int &lowest2, int &lowest3, int lowest[])
{
int smallest = 0;
lowest1 = arr[0].exam1;
lowest2 = arr[0].exam2;
lowest3 = arr[0].total;
for (int i = 0; i < SIZE; i++)
{
if (lowest1 > arr[i].exam1)
{
lowest1 = arr[i].exam1;
smallest = i;
}
if (lowest2 > arr[i].exam2)
{
lowest2 = arr[i].exam2;
smallest = i;
}
if (lowest3 > arr[i].exam3)
{
lowest3 = arr[i].exam3;
smallest = i;
}
}
for(int index = 0; index < INFO; index++)
{
if(index == 0)
lowest[0] = lowest1;
else if(index == 1)
lowest[1] = lowest2;
else if(index == 2)
lowest[2] = lowest3;
else
cout << "Fail!" << endl;
}
}
void calcHighest(StudentData arr[], int &highest1, int &highest2, int &highest3, int &highest4, int highest[])
{
int biggest = 0;
highest1 = arr[0].exam1;
highest2 = arr[0].exam2;
highest3 = arr[0].exam3;
highest4 = arr[0].total;
for (int i = 0; i < SIZE; i++)
{
if (highest1 < arr[i].exam1)
{
highest1 = arr[i].exam1;
biggest = i;
}
if (highest2 < arr[i].exam2)
{
highest2 = arr[i].exam2;
biggest = i;
}
if (highest3 < arr[i].exam3)
{
highest3 = arr[i].exam3;
biggest = i;
}
biggest = i;
}
for(int index = 0; index < INFO; index++)
{
if(index == 0)
highest[0] = highest1;
else if(index == 1)
highest[1] = highest2;
else if(index == 2)
highest[2] = highest3;
else
cout << "Fail!" << endl;
}
}
void getAverage(StudentData arr[], int size, double &average1, double &average2, double &average3,double average[])
{
int sum1 = 0, sum2 = 0, sum3 = 0;
for(int i = 0; i < SIZE; i++)
{
sum1 += arr[i].exam1;
sum2 += arr[i].exam2;
sum3 += arr[i].total;
}
average1 += static_cast<double>(sum1)/size;
average2 += static_cast<double>(sum2)/size;
average3 += static_cast<double>(sum3)/size;
for(int index = 0; index < INFO; index++)
{
if(index == 0)
average[0] = average1;
else if(index == 1)
average[1] = average2;
else if(index == 2)
average[2] = average3;
else
cout << "Fail!" << endl;
}
}
void getStd(StudentData arr[], double &std1, double &std2, double &std3,double &average1, double &average2, double &average3,double standardDeviation[])
{
double deviationSum1 = 0, deviationSum2 = 0, deviationSum3 = 0;
for(int i = 0; i < SIZE; i++)
{
deviationSum1 += pow((arr[i].exam1 - average1), 2);
deviationSum2 += pow((arr[i].exam2 - average2), 2);
deviationSum3 += pow((arr[i].exam3 - average3), 2);
}
std1 = sqrt(deviationSum1 / ((SIZE) - 1));
std2 = sqrt(deviationSum2 / ((SIZE) - 1));
std3 = sqrt(deviationSum3 / ((SIZE) - 1));
for(int index = 0; index < INFO; index++)
{
if(index == 0)
standardDeviation[0] = std1;
else if(index == 1)
standardDeviation[1] = std2;
else if(index == 2)
standardDeviation[2] = std3;
cout << "Fail!" << endl;
}
}
cout << " ";
}
void sort(StudentData arr[])
{
StudentData temp;
for (int i = 0; i < (SIZE - 1); i++)
{
for (int j = i + 1; j < SIZE; j++)
{
if (arr[i].last_name > arr[j].last_name)
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.