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...
Part 1 Write a program that reads a line of input and display the characters between...
Part 1 Write a program that reads a line of input and display the characters between the first two '*' characters. If no two '*' occur, the program should display a message about not finding two * characters. For example, if the user enters: 1abc*D2Efg_#!*345Higkl*mn+op*qr the program should display the following: D2Efg_#! 1) Name your program stars.c. 2) Assume input is no more than 1000 characters. 3) String library functions are NOT allowed in this program. 4) To read a...
USE C++!!!! Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to...
USE C++!!!! Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to meaningless characters, and decryption is used to transform meaningless characters into meaningful text. The algorithm that does the encryption is called a cipher. A simple encryption algorithm is Caesar cipher, which works as follows: replace each clear text letter by a letter chosen to be n places later in the alphabet. The number of places, n, is called the cipher key. For example, if...
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...
Hello, I'm learning how to code in C++ and am still getting used to using functions...
Hello, I'm learning how to code in C++ and am still getting used to using functions outside of int main(). Please help Sample Run Employee Management System Command Menu list - Display all employees view - View an employee add - Add an employee del - Delete an employee exit - Exit program Command: list 1. John Rink, [email protected], 415-123-4567 2. Mike Anderson, [email protected], 415-111-2222 Command: view Number (1 - 2): 3 Invalid number. Try again! Command: view Number (1...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT