Question

C Programming. Do not use a function in the solution. Assignment 6 This assignment focuses on...

C Programming. Do not use a function in the solution.

Assignment 6 This assignment focuses on using arrays.

Instructions Create a program called arrays.c that does the following:

1. Prompt the user for a string (<= 100 characters). (using the attached file: AS06Data.txt)

AS06Data.txt file contains the text "

Instructions: When your executing program displays "Enter string 1:" starting with T, select the line of text below, copy with ctrl-c, then  type ctrl-v



THIS IS a test of string 0123456789  +~_!)@()#($*%&^ stuff"

2. Display the frequency table showing the total number of characters entered by the user, the count for each character entered by the user, and the percentage of the total count that is attributed to each character. Display in the same order as the sample output below

The absolute frequency of a character is the number of times the character appears. For example, in the string "aaab" the absolute frequency of 'a' is 3, and the absolute frequency of 'b' is 1.

The relative frequency of a character is the absolute frequency divided by the total number of characters. For example, in the string "aaab" the relative frequency of 'a' is 3/4 = 0.75, and the relative frequency of 'b' is 1/4 = 0.25. Relative frequency * 100 will give you the result in percentage

Some help copied from the content section, lessening the chance to miss it:

• fgets

• getchar()

Sample Output Program: Array

Author: Gayathri Iyer

Enter string 1: THIS IS a test of string 0123456789 +~_!)@()#($*%&^ stuff

FREQUENCY TABLE

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

Char Count % of Total

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

ALL 58 100.00

" " 9 15.52

"!" 1 1.72

"#" 1 1.72

"$" 1 1.72

"%" 1 1.72

"&" 1 1.72

"(" 2 3.45

")" 2 3.45

"*" 1 1.72

"+" 1 1.72

"0" 1 1.72

"1" 1 1.72

"2" 1 1.72

"3" 1 1.72

"4" 1 1.72

"5" 1 1.72

"6" 1 1.72

"7" 1 1.72

"8" 1 1.72

"9" 1 1.72

"@" 1 1.72

"H" 1 1.72

"I" 2 3.45

"S" 2 3.45

"T" 1 1.72

"^" 1 1.72

"_" 1 1.72

"a" 1 1.72

"e" 1 1.72

"f" 3 5.17

"g" 1 1.72

"i" 1 1.72

"n" 1 1.72

"o" 1 1.72

"r" 1 1.72

"s" 3 5.17

"t" 4 6.90

"u" 1 1.72

"~" 1 1.72

Homework Answers

Answer #1

Please look at my code and in case of indentation issues check the screenshots.

---------------arrays.c----------------

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
   char inputString[1000];                       //create char array to store input string
   printf("Enter string 1: ");
  
   fgets(inputString, 1000, stdin);           //read string
   inputString[strlen(inputString)-1] = '\0';   //set newline into null character

   // Declaration and initialization of an array to store the char frequency
   int frequency[256] = {0};                   //we will use ASCII number of a character as an input

   int i;
   for(i = 0; i < strlen(inputString); i++){   //loop through each character in string
       frequency[inputString[i]]++;           //increase frequency for that char
   }
   int total = strlen(inputString);

   printf("\nFREQUENCY TABLE\n");
   printf("-------------------------------\n");
   printf("Char\tCount\t%% of Total\n");
   printf("-------------------------------\n");
   printf("ALL\t%d\t100.00\n", total);

   float percent;
   for(i = 0; i < 256; i++){
       if(frequency[i] > 0){                   //check if for freq is positive
           percent = (float) frequency[i]/ (float) total * 100;       //computer percent
           printf("\"%c\" \t %d \t %.2f \n", i, frequency[i], percent);
       }
   }  

   return 0;
}

--------------Screenshots--------------------

------------------Output-------------------

-----------------------------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.

Know the answer?
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
Similar Questions
This is C++ Note, for part 2 of this assignment, you DO NOT NEED to use...
This is C++ Note, for part 2 of this assignment, you DO NOT NEED to use arrays or vectors. All changes, calculations, etc should be performed in place ( in the file). You may need one or two structures that temporary hold data needed to be displayed, changed, etc. Part 2: Binary Files Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
C Programming I am trying to also print the frequency and the occurrence of an input...
C Programming I am trying to also print the frequency and the occurrence of an input text file. I got the occurrence to but cant get the frequency. Formula for frequency is "Occurrence / total input count", this is the percentage of occurrence. Can someone please help me to get the frequency to work. Code: int freq[26] = {0}; fgets(input1, 10000, (FILE*)MyFile); for(i=0; i< strlen(input); i++) { freq[input[i]-'a']++; count++; } printf("Text count = %d", count); printf("\n"); printf("Frequency of plain text\n");...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking...
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking a user-given number, and adding up all of the numbers between 1 and the given number. So if someone inputs 12, it should add 1 + 2 + 3 + 4 + … 9 + 10 + 11 + 12, and return the answer. However, you’ll be using two different methods to do this. The first method should utilize either a for loop or...
in the scheme programming language implement a game of rock paper scissors between a user and...
in the scheme programming language implement a game of rock paper scissors between a user and the computer. Only the following scheme subsets should be used: Special symbols (not case sensitive in our version (R5RS), but is in R6RS): a. Boolean: #t (else) and #f b. Characters: #\a, #\b ... #\Z c. Strings: in double quotes 3. Basic functions: a. quote b. car c. cdr d. c _ _ _ _ r, where each _ is either “a” or “d”...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write()...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write() and read() functions with binary                                                        data, where the data is not char type.              (Typecasting is required) Fill in the blanks, then enter the code and run the program. Note:   The data is int type, so typecasting is            required in the write() and read() functions. #include <iostream> #include <fstream> using namespace std; int main() {    const int SIZE = 10;   ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT