Question

using basic c++ and use no functions from c string library

b) Write a fragment of code (with declarations) that reads a pair of words from the keyboard and determines how many letters

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// d)

#include <iostream>

#include <time.h>

using namespace std;

int main() {

srand(time(NULL));

int dice[1000] = {0, 0, 0, 0, 0, 0};

for(int i=0; i<1000; i++)

{

int one = rand() % 8;

if(one == 6)

dice[1]++;

else if(one == 7)

dice[3]++;

else

dice[one]++;

}

for(int i=0; i<6; i++)

{

cout << i+1 << " occurred " << dice[i] << " times." << endl;

}

}

/*OUTPUT

1 occurred 147 times.

2 occurred 222 times.

3 occurred 135 times.

4 occurred 237 times.

5 occurred 135 times.

6 occurred 124 times.

*/

// Multiple questions are posted. Answered one. Please post one at a time. HOMEWORKLIB RULES.

Add a comment
Know the answer?
Add Answer to:
using basic c++ and use no functions from c string library b) Write a fragment of...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++ programming. Write a program that takes a string of input from the user and...

    Using C++ programming. Write a program that takes a string of input from the user and separates the string of words based on the premise that the string contains words whose first letter is uppercase. Then, display the phrase (or sentence) to a string in which the words are separated by spaces and only the first word of the phrase starts with an uppercase letter. For example, if the user enters "IAmTheTeacher", then the program would display: "I am the...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • 4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This...

    4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This function computes the number of appearances of each letter in the string word and stores them irn array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90 for the uppercase letters. You must account for uppercase and lowercase letter variants, which...

  • u also need to store the letters' ASCII number in the freq array 4. [8] Write...

    u also need to store the letters' ASCII number in the freq array 4. [8] Write a C function with prototype · void letter_freq(const char word[], int freq []); This function computes the number of appearances of each letter in the string word and stores them in array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • Program is in C++. Write a function named wordStatsPlus that accepts as its parameter a string...

    Program is in C++. Write a function named wordStatsPlus that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report: the total number of lines; total number of words; the number of unique letters used from A-Z, case-insensitively, and its percentage of the 26-letter alphabet; the average number of words per line (as an un-rounded...

  • Program is in C++.   Write a function named wordStatsPlus that accepts as its parameter a string...

    Program is in C++.   Write a function named wordStatsPlus that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report: the total number of lines; total number of words; the number of unique letters used from A-Z, case-insensitively, and its percentage of the 26-letter alphabet; the average number of words per line (as an un-rounded...

  • Can you write a program to convert a string from uppercase to lowercase and lowercase to...

    Can you write a program to convert a string from uppercase to lowercase and lowercase to uppercase depending on the user's input? In simple C++ please So for example if the input is Hello then the output should be hELLO

  • Question 2 Write a program that will read in a line of text up to 100...

    Question 2 Write a program that will read in a line of text up to 100 characters as string, and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespace, commas, an<d periods. When...

  • 2. How many positive integers less than 1000 are multiples of 5 or 7? Explain your answer using t...

    2. How many positive integers less than 1000 are multiples of 5 or 7? Explain your answer using the inclusion-exclusion principle 3. For the purpose of this problem, a word is an ordered string of 5 lowercase letters from the English alphabet (i.e., the 26 letters from a to z). For example, "alpha" and "zfaxr" are words. A subword of a word is an ordered string that appears as consecutive letters anywhere within the given word. For example, "cat" is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT