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
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.
Get Answers For Free
Most questions answered within 1 hours.