C++ :: Program That Counts Number Of Occurrence Of A Letter In A File

Feb 3, 2013

I need to create a program that asks the user for the filename, then counts the number of occurrence of each letter in that file.

Ex. if the file contains
Absacsac
asdasda

Output will be

a = 6
b = 1
c = 2
.
.
.
z = 0

This has been my program so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include <cstdlib>
void countingFunction(string sentence) {

[Code] .....

View 2 Replies


ADVERTISEMENT

C :: Euler Project - Number Letter Counts

Apr 30, 2013

I am working on Euler Project exercise number 17. Here is the problem from the website.

"If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?"

Code:
#include <stdio.h>
#include <string.h>
#define LENGTHOFHUNDRED 7
#define LENGTHOFONETHOUSAND 11
#define NUMSTART 1
#define NUMEND 1000

[Code] .....

View 8 Replies View Related

C++ ::  keyboard That Counts Frequency Of Occurrence Of All Letters Of Alphabet

Mar 24, 2013

c++ program which reads an input stream from the keyboard that counts the frequency of occurrence of all the letters of the alphabet

View 5 Replies View Related

C++ :: Replace 2nd Occurrence Of Letter?

Apr 27, 2013

i`m currently racking my brains out over this issue. How do i go about the x as the first occurrence of the letter?

lets say helxo , x is the 2nd occurrence of l. I will want to change back x into l

i have replaced it with x in the earlier step with this code...

string everySecondChar(const string &s,char source,char distance)
{
string t(s);
for(std::string::size_type even =0,pos=t.find(source,0);pos!=std::string::npos;pos=t.find(source,++pos))
{

[Code]....

i would like to reverse the process now, letting x becoming l again!

View 10 Replies View Related

C++ :: How To Replace 2nd Occurrence Of A Letter With X

Apr 21, 2013

Supposed i have a word hammer.

how am i suppose to search for the 2nd occurrence of the letter and then replace it with x?

example hammer will become hamxer

I thought about using replace for it, however i`m lost on how to find 2 occurrences of the same letter in the word.

string formatEncrypt(string message) {
int msgLength=message.length();
for(int i=0;i<msgLength;i++) {
if(message[i] == 'j' {
message[i]='i';

[Code] .....

at line 31 i tried to put a z into the alphabet that occurs twice.

this is what i have done so far

example: hello world

It will turn out as helzlo world

However i want to make the output appear as helzo world

View 6 Replies View Related

C++ :: Make Program That Counts Number Of Words / Lines And Vowels?

Mar 13, 2014

So I need to make a program that counts the number of words, lines, and vowels in a program. Punctuation and white spaces are not counted in any of the counts. I have this so far and the words, and lines work and are correct but I can't seem to get the vowel count to work.

#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <string>

[Code]....

View 1 Replies View Related

C/C++ :: Program To Read Sequence Of N Integers And Print Number With Maximum Occurrence

Mar 24, 2014

write a program in c to read a sequence of N integers and print the number that appears the maximum number of times in the sequence.

View 1 Replies View Related

C++ :: Program To Calculate A Grade Letter Into Number?

Feb 7, 2013

So I have to write a program to calculate a grade letter into a number.

Letter grades are A, B, C, D, and F, possibly followed by + or –. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F–. A + increases the numeric value by 0.3, a – decreases it by 0.3. If the letter grade is illegal (such as "Z"), then your output should be "INVALID LETTER GRADE"; If the combination is illegal (such as "A+" or "F-") then your output should be "INVALID GRADE COMBINATION"

Also the code should look like this
Enter your letter grade: C+
Grade value is [2.3]

// Input
cout << "Enter your letter grade: ";
string s;
cin >> s;

[Code].....

View 2 Replies View Related

C++ :: Program That Opens A File And Counts White Space Separated Words

May 17, 2013

Question is : Write a program that opens a file and counts the whitespace-separated words in that file.?

my answer is :

#include <iostream>
using namespace std;
#include <iostream>
#include <string>
#include <fstream>

int main() {
string filename = "Question 1.cpp"; // File name goes in here

[Code] ....

Now I am not sure if im suppose to get a msg saying : The file "Question 1.cpp" has 0 words.

im wondering is the question that im being asked, asking me to input a string of words and then the compiler when it builds and runs the program counts the word spaces.?

View 5 Replies View Related

C++ :: Program That Count Occurrence Of Character In Text File And Produce Histogram

Nov 18, 2014

Here is what i have so far:

#include<fstream>
#include<iostream>
#include<string>

[Code].....

I also need to do a loop that scan the count array and check if the element is bigger than the previous one.

View 1 Replies View Related

C++ :: Counts Number Of Words In A String That End With Ng

Dec 10, 2013

I am trying to write a code that counts the number of words in a string that end with ng.

I started with this but this just checks the end of the string. I need it to check everyword in the string and also count them up.

int main() {
string s;
cout << " enter string ";
getline(cin, s);
string end;
end = s.substr(s.length()-2, 2);
cout << end;
cout << endl;
return 0;
}

View 19 Replies View Related

C Sharp :: Call That Counts Number Of Entries In Database - Cast Error

Jul 14, 2013

I have an issue with a database call. I've got a database call that counts the number of entries in the database:

        private static Int32 dbCount() {
            SqlCommand cmd = new SqlCommand("SELECT COUNT (*) FROM Employees", conn);
            conn.Open();
            Int32 count = (Int32)cmd.ExecuteScalar();
            conn.Close();
            return count;
        }  

Afterwards I'm using this as a check throughout my application:

           if (dbCount > 0)  {
                // do something
            }  

When I execute this code I'm getting the following error: "Operator '>' cannot be applied to operands of type 'method group' and 'int'"

So I'm guessing it has something to do with the cast of the dbCount-object but I don't understand why as I already stated that the count-object to be an Int32.

View 3 Replies View Related

C/C++ :: Read Integers Into Array / Sort Numbers And Print Out Occurrence Of Each Number

Apr 6, 2014

My C programming class wants us to write a program to read integers into an array, sort the numbers and print out the occurrence of each number. I've tried everything that I can think of but the core dump is still occurring.

void countValues ( FILE *inf, int list[], int size ); /* Function prototypes. */
void printFrequencies( const int list[], int size );
int main (void) {
int status = EXIT_SUCCESS; /* defaulting status to success. */
FILE *inf = fopen( "numbers.txt", "r" ); /* input data file */

[Code] .....

View 6 Replies View Related

C :: Program That Counts Letters Of 3 Lines Of Input From User

May 26, 2013

So I am writing a program that counts the letters of 3 lines of input from the user. I am using a 3 x 80 character array as the "notepad". Upper and lower case characters are incremented on the same counter array.

Code:

/*Letters in a string*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void countAlphabet(char *);
/*Character counting array*/
int alphabet[26] = {0};

[Code]...

View 3 Replies View Related

C :: Program That Will Repeat K Times Each Single Occurrence Of A Vowel?

Jun 8, 2014

Repeat the vowel Problem 3 (0 / 0)Write a program that will repeat k times each single occurrence of a vowel in the input file "sp.txt" to a new file "output.txt". The first line of the input file contains only the parameter k. The first line (containing the parameter k) should not to be written in the output file.

I wrote the code but i cant figure out something. i read the file, i found the vowels but then i cant print them.

Code:
#include <stdio.h>#include <string.h>
#include <ctype.h>
#define MAX 100
int checkvowel(char c)

[Code].....

View 6 Replies View Related

C++ :: Open A File And Counts White Space Separated Words

May 3, 2013

Write a program that opens a file and counts the whitespace-separated words in that file.?

My code that i wrote for this example is as follows...

#include <iostream>
using namespace std;
#include <iostream>
#include <string>
#include <fstream>
int main() {
string filename = "Question 1.cpp"; // File name goes in here

[Code] ....

Is this correct or am i missing something?

View 6 Replies View Related

C :: How To Initialize A Variable That Is Not A Letter Or Number

Feb 25, 2014

In C how can I initialize a variable that is not a letter or number? For example with a number I can :

Code:

int i = 5;
for ( i = 0; i <=5; i++ );
printf( "%d", i ) This would display a row of 5's

but what if I wanted to display a row of -----? What I am trying to do is read in a simple txt file, around the file I want ----1----2-----3 ect ect on the top ----a----b-----c down the side Then I want to be able to change the file at lets say position c2 and save it. This is the early stages of my attempt to set up a editable table.

View 3 Replies View Related

C :: Magic Letter For Making A Constant Number Be Int?

Sep 26, 2014

For example if I have typed 0xFF (a literal hex number that represents the value 255 for Unsigned Char or -1 for Signed Char) in part of my program. That 0xFF is treated as a Char not an Int, because the value is within the range supported by Char, the C compiler always tries to use the smallest datatype possible for the number that is needed for a literal value like this.

Unfortunately because Signed Char is the default Char type, 0xFF is translated into -1. I am wanting to use it to represent 255. So I'm trying to tell the compiler that 0xFF should be interpreted as either an Int or an Unsigned Char. How do I do this?

I already tried typing it with the magic letter "I", like this: 0xFFI

But that didn't work. What is the correct way to do this?

View 4 Replies View Related

C++ :: Differentiate A Word / Letter And Number In A String

Aug 22, 2014

I have one string from user. Let say,

"The deviceId is 2"....but user also can give input like this..
"The deviceId is a".

I just need to know how to differentiate a word/letter and number in the string.

View 1 Replies View Related

C++ :: Crypt Arithmetic Puzzle - Replace Each Letter As S Number

Oct 28, 2013

Dont know how to replace each letter as s number ... this is the question i was given ...

In cryptarithmetic puzzles, mathematical equations are written using letters. Each letter can be a digit from 0 to 9, but no two letters can be the same. Here is a sample problem:

SEND + MORE = MONEY

A solution to the puzzle is S = 9, R = 8, O = 0, M = 1, Y = 2, E = 5, N = 6, D = 7.

Write a program that finds a solution to the cryptarithmetic puzzle of the following:

TOO + TOO + TOO + TOO = GOOD

The simplest technique is to use a nested loop for each unique letter (in this case T, O, G, D). The loops would systematically assign the digits from 0 to 9 to each letter. For example, it might first try T=0,O=0,G=0,D=0, thenT=0,O=0, G = 0, D = 1, then T = 0, O = 0, G = 0, D = 2, etc., up to T = 9, O = 9, G = 9, D = 9. In the loop body, test that each variable is unique and that the equation is satisfied. Output the values for the letters that satisfy the equation.

View 13 Replies View Related

C/C++ :: Filling Array With Non Letter Char And It Outputs A Number?

Sep 2, 2014

I am trying to fill an array with blank spaces and instead i get the number 32 over and over, i think this is the ANSI code for that character. how do i get the character itself?

char values[max];
for(o=0;o<=max;o++)
{
values[o]=' ';
printf("%2d ", values[o]);
}
printf("
");

View 1 Replies View Related

C Sharp :: Assign A Specific Number To Each Letter In A Sentence?

Feb 14, 2014

I have a string - a whole sentence that I want to assign a number to each letter, space, comma and period etc. So all "A's" will have the same number, all "B's" will have another number etc. I don't want to use the ASCII numbers because they all need to be sequential and some of the punctuation isn't. I have put the string into a char array to separate each character out and was thinking about running it through a loop with if statements for each letter and assigning numbers there and then saving the numbers in the order they appear into a list as a string but I keep coming up with errors so I don't know how to do it or if there is a better way to accomplish what I'm trying to do.

View 1 Replies View Related

C++ :: Enter Number Or Letter And Sort In Ascending Or Descending Order

Jan 8, 2013

Assignment:

1. Choose what to enter NUMBER or LETTER.
2. Choose type of sorting ASCENDING or DESCENDING.

#include<iostream.h>
#include<conio.h>
main() {
int x,y,z;
cout<<"choose Number or letter
1.number
2.Letter";

[Code] ....

View 9 Replies View Related

C++ :: Program Will Echo Letter (User Input) And Output Name Of The Day Of Week

Oct 21, 2012

Write a C++ program that does the following:

Prompt the user to enter a day of the week as M (or m), T, W, R, F, S, and U for Monday through Sunday respectively. The user may enter an upper or lower case letter.

When the user enters a character, the program will echo the letter and output the name of the day of the week.

Provide an error trap that reads something like "you have entered an invalid letter; program aborting." Suggestion: use a switch statement with the error trap as the default condition. it is not necessary to prompt for multiple inputs.

So I know how to get the program to echo back the letter and everything. What I am a little confused about is: will I have to define all the letters as their respective day? eg. make M== Monday. And if I do have to do that how would I get it to accept Upper and Lower case letters and recognize that that letter is == monday ect. ect.

Also my main problem is the switch statement as the error trap. I have never used the switch statement, but I know what they do. I just don't really understand how I would use it for an error trap. Am I suppose to just make a case for every other letter in the alphabet other then M T W R F S and U? Even if I do that then what if the user enters a number instead of a letter?

View 4 Replies View Related

C :: How To Read Only The First Capital Letter From A File

Dec 25, 2014

I'm supposed to count the number of first capital letters in a string. I've written a code that counts every uppercase letter, and it turns out that this is not what the assignment is about. For example, the input "JAMES, How Are you?" should return an output of 3 (mine would return 7 in this case). Only J, H, A need to be counted.

Code:

#include <stdio.h>
#include <string.h>
#define MAX 100
void WriteToFile() {
FILE *f = fopen("text.txt", "w");
char c;
while((c = getchar()) != EOF) {

[Code]...

How do I fix this?

View 2 Replies View Related

C :: Open New Text File With First Letter Of Line On A Certain Directory

May 23, 2013

I'm reading from stdin a line. With that line, I should open a new textfile with the first letter of that line on a certain directory. My code is the following :

Code:

int main() {
char line[BUFSIZ];
FILE *ptr_file;
int x;
while(fgets(line,BUFSIZ,stdin) != NULL){

[Code] ....

char caminho[] is the directory in which I want to create the text file and chave will be the first letter of the line in stdin.

How am I supposed to use strcat to get these two together in a string to then use ptr_file =fopen(caminho, "w");

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved