1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
choli [55]
3 years ago
5

You are given a C program "q2.c" as below. This program is used to calculate the average word length for a sentence (a string in

a single line): Enter a sentence: It was deja vu all over again. Average word length: 3.42 For simplicity, the program considers a punctuation mark to be part of the word to which it is attached. And it displays the average word length to two decimal places.
Engineering
1 answer:
MrMuchimi3 years ago
5 0

Answer:

  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5.    char sentence[100];
  6.    int i;
  7.    int wordCount = 1;
  8.    int charCount = 0;
  9.    float averageLength;
  10.    
  11.    printf("Enter a sentence: ");
  12.    gets(sentence);
  13.    
  14.    for(i = 0; i < strlen(sentence); i++){
  15.        if(sentence[i] != ' '){
  16.            charCount++;
  17.        }else{
  18.            wordCount++;
  19.        }    
  20.    }
  21.    
  22.    averageLength = (float)charCount / wordCount;
  23.    printf("Average word length: %.2f", averageLength);
  24.    
  25.    return 0;
  26. }

Explanation:

Firstly we need to import the string.h library  as we need to use strlen method to estimate the length of the input string (Line 2).

To estimate the average word length for an input sentence, we can calculate the total of characters in the sentence and then divide it by the total number of words. To do so, we first get the input sentence from the user (Line 11-12). Next, use a for loop to traverse through the sentence character by character and check if the character is not a space ' ', increment charCount by one. Whenever there is a space, this mark an end of a word and therefore increment wordCount by one (Line 18).

After the loop, we can calculate the average word length by dividing the charCount by wordCount and print the output to two decimal places (Line 22- 23).  

You might be interested in
What is the purpose of having a ventilation system on board a motorized vessel?.
chubhunter [2.5K]

The purpose of having a ventilation system on board a motorized vessel is : To remove flammable gas from a vessel to avoid explosions.

<h3>Meaning of ventilation system</h3>

A ventilation system can be defined as a system that allows for removal of gases from a vessel to the atmosphere.

A Ventilation system is very important in every motorized vessel because they help to eliminate or remove flammable gases that are dangerous and are liable to explode when held in a large amount in the engine.

In conclusion, The purpose of having a ventilation system on board a motorized vessel is to remove flammable gas from a vessel their by avoiding explosions.

Learn more about Ventilation System: brainly.com/question/1687520

#SPJ4

4 0
2 years ago
Create a program named PaintingDemo that instantiates an array of eight Room objects and demonstrates the Room methods. The Room
Serggg [28]

Answer:

Explanation:

Code used will be like

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace PaintingWall

{

class Room

{

public int length, width, height,Area,Gallons;

public Room(int l,int w,int h)

{

length = l;

width = w;

height = h;  

}

private int getLength()

{

return length;

}

private int getWidth()

{

return width;

}

private int getHeight()

{

return height;

}

public void WallAreaAndNumberGallons()

{

Area = getLength() * getHeight() * getWidth();

if (Area < 350)

{

Gallons = 1;

}

else if (Area > 350)

{

Gallons = 2;

}    

Console.WriteLine ("The area of the Room is " + Area);

Console.WriteLine("The number of gallons paint needed to paint the Room is " + Gallons);

}

 

}

class PaintingDemo

{

static void Main(string[] args)

{

int l, w, h;

Room[] r = new Room[8];

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

{

Console.WriteLine("Room "+(i+1));

Console.Write("Enter Length : ");

l = Convert.ToInt32(Console.ReadLine() );

Console.Write("Enter Width : ");

w = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter Height : ");

h= Convert.ToInt32(Console.ReadLine());

r[i] = new Room(l,w,h);

Console.WriteLine();

}

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

{

Console.WriteLine("Room " + (i + 1));

r[i].WallAreaAndNumberGallons();

}

Console.ReadKey();  

}

}

}

3 0
3 years ago
Describe three differences between liquids and gases in fluid power systems.<br> Help !!!
scoundrel [369]
Gases, liquids and solids are all made up of atoms, molecules, and/or ions, but the behaviors of these particles differ in the three phases. ... gas are well separated with no regular arrangement. liquid are close together with no regular arrangement. solid are tightly packed, usually in a regular pattern.
3 0
3 years ago
A vertical piston-cylinder device initially contains 0.2 m3 of air at 20°C. The mass of the piston is such that it maintains a c
Ann [662]

Answer:

Amount of air left in the cylinder=m_{2}=0.357 Kg

The amount of heat transfer=Q=0

Explanation:

Given

Initial pressure=P1=300 KPa

Initial volume=V1=0.2m^{3}

Initial temperature=T_{1}=20 C

Final Volume=V_{2}=0.1 m^{3}

Using gas equation

m_{1}=((P_{1}*V_{1})/(R*T_{1}))

m1==(300*0.2)/(.287*293)

m1=0.714 Kg

Similarly

m2=(P2*V2)/R*T2

m2=(300*0.1)/(0.287*293)

m2=0.357 Kg

Now calculate mass of air left,where me is the mass of air left.

me=m2-m1

me=0.715-0.357

mass of air left=me=0.357 Kg

To find heat transfer we need to apply energy balance equation.

Q=(m_{e}*h_{e})+(m_{2}*h_{2})-(m_{1}*h_{1})

Where me=m1-m2

And as the temperature remains constant,hence the enthalpy also remains constant.

h1=h2=he=h

Q=(me-(m1-m2))*h

me=m1-me

Thus heat transfer=Q=0

6 0
3 years ago
What type of oil pressure gauge should be used when
liq [111]

Answer:

The mechanical gauge would be the one for the job

Explanation:

6 0
2 years ago
Other questions:
  • Tim was recently released from his last job. He was very rigid and would not change a product design once he began a project. He
    7·1 answer
  • Water drains at a constant rate through a saturated soil column with a diameter of 1.5 feet and a height of 3 feet. The hydrauli
    11·1 answer
  • Please Help !!
    5·1 answer
  • 11. Technicians A and B are discussing
    12·1 answer
  • Sun of first 1 nayural numbers​
    7·2 answers
  • calculate force and moment reactions at bolted base O of overhead traffic signal assembly. each traffic signal has a mass 36kg,
    6·1 answer
  • Which of the following is not caused by alcohol?
    10·2 answers
  • Merchandise without an expiration date like electronics, tools and home goods typically have a longer
    15·1 answer
  • What is anthropology? Discuss the type of anthropology?
    5·2 answers
  • Describe two other safe driver skills a driver should use when driving in this road condition
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!