Scala: Write a Program as elegantly as possible
Given a piece of text, create a histogram of letter pairs (order from high to low). For instance, for the text, “this is a good thing”,
the letter pairs are: th, hi, is, is, go, oo, od, th, hi, in,
and ng. (ignore a) The histogram will be:
th: 2, is: 2, hi: 2 go: 1, oo: 1, od: 1, in: 1, ng: 1
Sample Input/Output:
Enter text: this is a good thing Histogram: th: 2, is: 2, hi: 2 go: 1, oo: 1, od: 1, in: 1, ng: 1
Enter text: coooooool Histogram: oo: 6, co: 1, ol: 1
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char sentence[10],letter_pair[9][2];
//Enter the string
printf("Enter a string\n");
scanf("%s", sentence);
printf("The entered string is:
%s\n", sentence);
//
//generate histrogram
int freq=0;
int hist[strlen(sentence)-1];
for(int i=0;i<strlen(sentence);i++)
{
for(int
j=0;j<strlen(sentence)-1;j++)
{
for(int
k=0;k<2;k++)
{
if (sentence[i] != letter_pair[j][k])
{
letter_pair[j][k]=sentence[i++];
}
else
{
hist[j]=++freq;
}
}
hist[j]=++freq;
i=i-2;
}
}
printf("The histogram of entered string is:\n");
for (int x=0;x<strlen(sentence)-1;x++)
{
for(int y=0;y<2;y++)
{
printf("%s :",
letter_pair[x][y]);
}
printf(" : %d\n", hist[x]);
}
}
Scala: Write a Program as elegantly as possible Given a piece of text, create a histogram...
Scala: Write and test a Program as elegantly as possible Given a piece of text, create a histogram of letter pairs (order from high to low). For instance, for the text, “this is a good thing”, the letter pairs are: th, hi, is, is, go, oo, od, th, hi, in, and ng. (ignore a) The histogram will be: th: 2, is: 2, hi: 2 go: 1, oo: 1, od: 1, in: 1, ng: 1 Sample Input/Output: Enter text: this is...
Write a program named text_indexing.c that does the following: Reads text and stores it as one string called text. You can read from a file or from the user. (In my implementation, I read only one paragraph (up to new line) from the user. With this same code, I am able to read data from a file by using input redirection (executable < filename) when I run the program. See sample runs below). You can assume that the text will...
Question 1 CSEB113 Write a program to create customer's bll for an electrical appliance company. Assume the company sells only three different products: TV, VCR and CD player. The unit prices are RM3000, RM500 and RM300 respectively. The program must read the quantity of each piece of the items purchased from the user. It then calculates the cost of each item, the subtotal and the total cost after an 6% of GST. Your program must use the following functions, given...
Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...
Please Code in Java and follow the directions given
Thanks
Program required
Directions
.A palindrome is a string that reads the same forward and backward, i.e., the letters are the same whether you read them from right to left or from left to right. Examples: 3 a) radar à is a palindrome b)Able was I ere I saw Elba à is a palindrome e good à not a palindrome Write java program to read a line of text and tell...
JAVA, please You must write a robust program meaning that your program should not crash with any given data. Data validation must be done any time that user enters an input. Write a program that 1. Gets an infix expression form the user and evaluate the expression using stack ADT a. Finds the postfix equivalent of the given infix expression b. Evaluate the created postfix expression. c. Note: your program should not crash when you enter an invalid expression such...
using java
Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...
In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...
in c++ Write a program that allows the user to type in any one-line question and then answers that question. Your program won't really respond to the question, rather it will read a random response from a file. Requirements Your program should have a function called getQuestion() which prompts the user for a question and returns the number of characters in the question (including spaces and punctuation, not including the ending newline). If the user enters an empty string they...
Program 2 #include #include using namespace std; int main() { int total = 0; int num = 0; ifstream inputFile; inputFile.open("inFile.txt"); while(!inputFile.eof()) { // until we have reached the end of the file inputFile >> num; total += num; } inputFile.close(); cout << "The total value is " << total << "." << endl; Lab Questions: We should start by activating IO-exceptions. Do so using the same method in Step 3 of the Program 1 assignment above, except that instead...