Reference no: EM13938448
I'm in dire need of help with coding this function/small program. I have 2 codes that I am working with just need one tha works well. Any help that can be provided would be appreciated greatly.
How it should work:
Write a function that accepts a pointer to a string as an argument and returns the number of words contained in the string.
Must actual count the number of words. User must be able to input a stringand then pass the string to the function. The function must also display the average number of letters in each word.
Codes that I am working with below:
1.)
----------------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include <iostream>
#include <iostream>
#include <cstring>
#include <ctype.h>
using namespace std;
int main ()
{
const int size = 5;
char WordString[size];
string sentence;
int wordlength = 5;
int wordcount = 0;
int i = 0;
cout<<"Enter a string or sentence: ";
cin.getline( WordString, size );
while( i <= sentence.length() )
{
if( isalpha( sentence[i] ))
{
wordlength++;
}
else if ( wordlength > 0 )
{
wordcount++;
wordlength = 5;
}
i++;
}
cout<<"There are " << wordcount << "words in this sentence."<< endl;
cin.get();
return 0;
}
_______________________________________________________________________
2.)
Tried working with this one also but program doen't allow me to do anything. Exits to early
-----------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
char abcd[100]; //string
int wordcnt=0; //word counter!
fflush(stdin);
cout << "\nEnter string: ";
cin.getline(abcd,wordcnt);
if(abcd[0]!=' ') wordcnt++; //account for the first word
for(int i=0; abcd[i]!='\0'; i++)
{
if(abcd[i]==' ')
{
//increment i until non-space char is found
while(abcd[i]==' ')
i++;
//account for spaces at end and increment wordcnt
if(i <= strlen(abcd))wordcnt++;
}
}
cout << "\n\nWord Count: " << wordcnt;
cin.get();
return 0;
}
How lymphatic system complements function of cardiovascular
: Explain the overall function of the entire cardiovascular system including all three components. (Do not, for example, say that the cardiovascular system's function is to circulate blood. That leaves out the function of blood itself.)
|
Discuss how the innovation component fits
: Your task is to visit UBER web site and discuss how the innovation component fits within what has been taught in this course. You will specifically discuss UBER in terms of ethics, security and organizational aspects.
|
Financial statement-calculate the operating and cash cycles
: Consider the following financial statement information for the Ayala Corporation: Item Beginning Ending Inventory $ 10,400 $ 11,400 Accounts receivable 5,400 5,700 Accounts payable 7,600 8,000 Credit sales $ 84,000 Cost of goods sold 64,000 Calculate..
|
Value and direction of a single resultant force
: Determine mathematically the value and direction of a single resultant force which when acting upon the plate shown below would effectively replace the forces shown.
|
Function that accepts a pointer to a string as an argument
: Must actual count the number of words. User must be able to input a stringand then pass the string to the function. The function must also display the average number of letters in each word.
|
Frank sent invoices to his customers
: Frank Crosby (who has never owned or run a business before) started a lawn mowing business (Crosby's Cutters) as a temporary job/business which he intended to run until he started his business degree at the University of Woop Woop in Semester 2, 2..
|
Two mutually exclusive investment projects for the firm
: As a financial analyst for a large firm you are investigating two mutually exclusive investment projects for the firm, project A and project B. After your analysis you find that the IRRA>IRRB, but that the NPVA
|
Provide the necessary journal entries for kinsella
: Kinsella, Inc., has a gross payroll of $8,000 for the pay period. Provide the necessary journal entries for Kinsella to record these payroll taxes.
|
Determining the effect of process parameters
: You are required to write a mini project that is structured in such a way as to answers all the questions contained within the project description.
|