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
ADVERTISEMENT
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
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
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
Apr 28, 2015
#include <fstream>
#include <iostream>
#include <string>
[Code].....
When I try to run my program I get:
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:UsersDocumentsVisual Studio 2010ProjectsCS 111Lab10Lab10DebugLab10.exe : fatal error LNK1120: 1 unresolved externals
What I'm trying to do is get my program to count the number of words in an inputted data file. I've attached the assignment directions
Attached File(s) : lab10_data_.zip (9.27K)
View 4 Replies
View Related
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
Dec 20, 2013
I have written below program to count number of words and lines and print the all the words.
#include <iostream>
using namespace std;
#include<fstream>
#include<string.h>
int main() {
ofstream outfile;
[Code] .....
Its compiling fine but when executed its displaying I infinite times...
View 3 Replies
View Related
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
View Related
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
Feb 5, 2015
I trying to write a program able to read a number up to 3 digits and display it in words. What to do first.
View 1 Replies
View Related
Jan 31, 2014
I want to count number of words from my textfile and then make the first word ToUpper and second word ToLower and do that for the rest of the textfile.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication3 {
internal class Program {
private static void Main(string[] args) {
[Code] ....
View 14 Replies
View Related
Oct 12, 2013
i want to convert the Digits in words.I have already a code but in my code the value is coming like for ex:-540000(Five hundered and Fourty Thousand ).but i want Five Lakh and Fourty thousand.
View 4 Replies
View Related
Jan 29, 2012
Write a program that prompts the user for the name of a file. Then it opens the file, and counts the number of words and lines in the file, and prints out those counts.
I think I possibly could somehow use a counter to increment using getLIne() until getLine() returns NULL, but the problem is, I'm worried if I try that, a file that looks like this:
Bla bla bla bla bla lkfdljkfaklafdskjladsjkdfkjlkdfjdfshafdsjkjrerjkkjfaddjkfsafkjdjakdfsjkasfjkjkfdskjldfjkfjkdjfkdsakdjfkjfdkjdfskjfdsk
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjdfkerea
blkjadkjlfdskjldfkjlfdkjfdjkdfsjkldfskljfksfdljfd
Only register four lines and not get the one after the fourth line.
So I was thinking of something like
Code:
#include <iostream>
#include<ifstream>
#include<cstring>
#include<string>
#include<vector>
#include <cstdlib>
using namespace std;
iostream keyboard;
ifstream file;
iostream cin;
[Code] .....
Did I do that right? Will that count the number of words and number of lines correctly?
View 14 Replies
View Related
Oct 2, 2014
I am trying to write a program in C to reverse a string .
Example - This is America
output - America is This
I have thought of two ways of doing this question
1) using 2D arrays ( no pointer)
2) Using Strings and pointer
Code:
#include<stdio.h>
#include<string.h>
main()
}
[code]....
View 4 Replies
View Related
Dec 4, 2013
I want to print the words of a sentence, given as a string..But I have a problem with the end of the sentence, and cannot find the bug....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char str[80]="This is a sentence";
int main(){
}
[code].....
View 7 Replies
View Related
Feb 3, 2015
"Type a function that take in a string containing numbers and others characters and print on stdout all the numbers contained into the string, where for number is mean every maximal numerical sequence, of numbers not separed by spaces. Numbers printed on exit must be separated by commas. For example, if i put in the function the string "paje27hg78 2k f562" my function must print:
27, 78, 2, 562 "
So i started my code like so: (I WANT TO NOTICE THAT WE HAVE ONLY USED IOSTREAM AND FSTREAM LIBRARY FOR NOW, SO DON'T USE OTHERS LIBRARY ELSE MY TEACHER WON'T CORRECT MY HOMEWORK!)
#include <iostream>
#include <fstream>
using namespace std;
[Code].....
View 18 Replies
View Related
May 19, 2014
I have a challenge to replace all the words "you" in a sentence that is entered by a user to "u". I have got this working but my code is also changing yourself to urself which it should not be doing.
#include <iostream>
#include <string>
using namespace std;
string shortenMsg (string smsP) {
string sentence = smsP;
string word1 = "you";
string word2 = "u";
[Code] .....
View 3 Replies
View Related
Aug 13, 2013
The basic idea of this exercise is to generate words from a user-input, seven-digit number(a phone number). The code runs, but for some reason, I can't get it to print the numbers into the file.
Code:
/*Write a program that will generate a word based on a randomly generated, seven-digit number. there should be 2187 possible words. Avoid "phone numbers" that begin with 0 or 1*/
#include<stdio.h>
#define PHONE 7
void wordGenerator(int number[]);
void wordGenerator(int number[]) {
//loop counters for each digit in the number
[Code] ....
View 3 Replies
View Related
Jan 26, 2015
I got a homework that require to count number of words in a text file and also display the first and last 10 words of the text file to the console. I have finished the counter problem and now I struggle showing the first and last 10 words.
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int tokenize(string sentence, string tokenizedWords[]);
[code]....
View 2 Replies
View Related
Nov 24, 2014
I'm trying to create a small program to reverse every alternate words in a string.
OUTPUT: The esoum was thgauc in a peg.
#include<iostream>
#include<string>
using namespace std;
int main() {
string sentence, reversed_sentence, buffer;
[code].....
View 6 Replies
View Related
Nov 25, 2014
I'm trying to reverse every even word in a string (not all of it). But I keep getting an empty output.
For example:
The mouse was caught in peg.
The esmou was thgauc in gep.
Underlined words (even words)
#include<iostream>
#include<string>
using namespace std;
int main()
{
string text, result, temp;
int word_count(0);
cout << "Enter a sentence: ";
[Code]...
View 1 Replies
View Related
Nov 23, 2014
How do reverse every alternate words in a string that I read into my program:
e.g. The mouse was caught in a clothes peg.
reversed (including the full stop)
The esoum was thguac in a clothes gep.
I could program it to reverse the whole sentence. But no clue how to reverse certain words such as every even word. Do I need a function and/or loop to solve this?
#include<iostream> // allow input and output
#include<string> // allow for larger entries of characters
using namespace std;
int main() {
string sentence, reversed_sentence;
[Code] ....
View 4 Replies
View Related
May 16, 2014
I have a problem with my code. You are given a sentence and you should censor the 4 letter words within the sentence.
#include<iostream>
#include<string>
using namespace std;
int main () {
int N;
cin>>N;
int k,j,counter=0;
[Code] ....
View 1 Replies
View Related
Jun 13, 2014
string answer;
cout<<"5.Newton's which law states that F=ma?";
cin>>answer;
if (answer == "newton's second law")
[Code].....
View 6 Replies
View Related
Feb 11, 2013
In my little experiment i am trying to get the compiler to recognize 1 word with 2 parts from a list of names.
For example: if the user wanted to choose "candy bar", from a list of items which include: "candy bar", "cat", "dog"
My current code can recognize words without a space like cat and dog. But how can i recognize candy bar?
I tried using getline but its of no use.
View 2 Replies
View Related
Jul 23, 2014
I am trying to read user input for recipe ingredients which must include a ingredient name, and may include a quantity and a unit. Example: Stone ground flour 2 cups or Sugar 1 Tbsp or Milk. The problem I am having is that the string gets cut off after a space when multiple words are used for the ingredient name.
cin.ignore();
string line;
getline(cin, line);
istringstream record(line);
string name;
string name2;
int quantity = 0;
string unit;
record>>name>>quantity>>unit;
View 1 Replies
View Related