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
Leto [7]
2 years ago
8

5.23 LAB: Contains the character

Computers and Technology
1 answer:
torisob [31]2 years ago
7 0

Answer:

In C++:

#include<iostream>

#include<vector>

using namespace std;

int main() {

int len;

cout<<"Length: ";  cin>>len;

string inpt;

vector<string> vect;

for(int i =0;i<len;i++){

  cin>>inpt;

  vect.push_back(inpt); }

char ch;

cout<<"Input char: ";  cin>>ch;  

for(int i =0;i<len;i++){

  size_t found = vect.at(i).find(ch);  

      if (found != string::npos){

          cout<<vect.at(i)<<" ";

          i++;

      }

}  

return 0;

}

Explanation:

This declares the length of vector as integer

int len;

This prompts the user for length

cout<<"Length: ";  cin>>len;

This declares input as string

string inpt;

This declares string vector

vector<string> vect;

The following iteration gets input into the vector

for(int i =0;i<len;i++){

  cin>>inpt;

  vect.push_back(inpt); }

This declares ch as character

char ch;

This prompts the user for character

cout<<"Input char: ";  cin>>ch;  

The following iterates through the vector

for(int i =0;i<len;i++){

This checks if vector element contains the character

  size_t found = vect.at(i).find(ch);  

If found:

      if (found != string::npos){

Print out the vector element

          cout<<vect.at(i)<<" ";

And move to the next vector element

          i++;

      }

}  

You might be interested in
HURRY HELP THIS IS FOR CODING !!!! What are some real-life situations that require a program that is iterative? Include at least
Degger [83]

Answer:

A health service, a sales service, a social network, all because they require you to make a request to return a result

5 0
3 years ago
Read 2 more answers
create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines.** Each m
jok3333 [9.3K]

Answer:

The Java code is given below

Explanation:

import java.io.*;

import java.util.Scanner;

import java.util.ArrayList;

public class StringCheck{

//There are several implementation approaches. This is one example framework/outline which might be helpful. Please feel free to try other approaches.

public static void checkWord(String word) throws Exception {

// Uses charAt method to test if the first letter of string variable word

// is a character. If not, throw new exception

if(Character.isLetter(word.charAt(0))){

 return;

}else{

 throw new Exception("This is not a word");

}

}

public static String getWord() {

// Declare a local scanner

// Prompt the user to enter a word

// Think about using a loop to give the user multiple opportunities to correctly enter a string

// Read into a string

// Call checkWord method passing the string as a parameter

// checkWord can throw an exception; call checkWord in a try/catch block

// Return the string to main if a valid string

Scanner sc = new Scanner(System.in);

boolean st = true;

String word = null;

while(st){

 System.out.println("Enter a Word : ");

 word = sc.next();

 try{

  checkWord(word);

  st = false;

 }catch(Exception e){

  System.out.println(e);

  st = true;

 }

}

sc.close();

return word;

}

public static void writeFile(String[] arrayToWrite, String filename) throws IOException {

// Example using FileWriter but PrintWriter could be used instead

// Create a FileWriter object

FileWriter fileWordStream = new FileWriter(filename);

// Use a loop to write string elements in arrayToWrite to fileWordStream

for(int i = 0;i<arrayToWrite.length;i++){

fileWordStream.write(arrayToWrite[i]+System.lineSeparator());

}

fileWordStream.flush();

fileWordStream.close();

// In the loop use the lineSeparator method to put each string on its own line

}

public static ArrayList readFile(String filename) throws FileNotFoundException, IOException {

// Declare local ArrayList

ArrayList<String> words = new ArrayList<>();

// Create a new File object using filename parameter

File file = new File(filename);

// Check if the file exists, if not throw a new exception

if(!file.exists()){

 throw new FileNotFoundException("File not Found");

}

// Create a new BufferedReader object      

Scanner fsc = new Scanner(file);

// use a loop and the readLine method to read each string (on its own line) from the file

while(fsc.hasNextLine()){

words.add(fsc.nextLine());

}

fsc.close();

// return the filled ArrayList to main

return words;

}

public static void main(String[] args) {

// create a string with literal values to write to the file

String[] testData = {"cat", "dog", "rabbit"};

// Create an ArrayList for reading the file

ArrayList<String> words = new ArrayList<>();

// Declare a string variable containing the file name "data.txt"

String file = "data.txt";

// Call getWord, assign the returned string to a variable and display it

String word = getWord();

System.out.println("The word is : "+word);

// Call writeFile and readFile methods in a try block

try{

writeFile(testData,file);

words = readFile(file);

// Printout the contents of the ArrayList after the call to readFile

for(int i = 0;i<words.size();i++){

 System.out.println(words.get(i));

}

}catch(FileNotFoundException e){

System.out.println(e);

}catch(IOException e){

System.out.println("IOException: error occured in input output");

}

// catch two types of exceptions

}

}

4 0
4 years ago
All of the following are advantages of database-stored information, except: Question 3 options: 1) Reduced information redundanc
enot [183]

Answer:

3) Reduced information integrity.

Explanation:

This is not an advantage, Information integrity is a key factor when storing information on a database. As multiple users will access it, they will need this data to be authentic and dependable. Any reduction in information integrity is a great disadvantage.

5 0
3 years ago
If a star system 30 parsecs distant is found to be broadcasting intelligent radio signals, then their news is already approximat
IrinaK [193]

Answer:

97.85 years, approximately.

Explanation:

Light travels at a <em>constant</em> speed of 186,000 mi/seg or 300,000km/seg accross the Universe (in vacuum conditions). Radio waves are also part of the electromagnetic spectrum, and they also travel at the same speed as Light does.

A light-year is a measure of the distance that Light travels during a year, that is,  5.88 trillion miles. Light travels the same distance per year because its speed is <em>constant</em>, and this is an excellent property that scientists take advantage to measure distances.

A parsec is 3.26 light-years (19 trillion miles), and (a very important datum to solve this question) one light-year is 0.306601 parsec, that is, in a year Light travels 0.306601 parsec at a <em>constant</em> speed. The same would happen with intelligent radio signals broadcasted from a distant star system.

So, considering all these facts, it is a matter of proportions to solve this question (mostly because speed of Light is constant):

\frac{1 year}{0.306601 parsec} = \frac{X years}{30 parsecs}

x =\frac{1 year * 30 parsec}{0.306601 parsec}

x = \frac{30}{0.306601} years

x = 97.84704 years or,

x = 97.85 years, approximately.

In other words, Light spends 97.85 years (terrestials) to travel 30 parsecs.

Likewise, radio waves travel at the same speed, so they spend the same years (97.85 years) travelling across the Universe to be finally detected by a radiotelescope located, for instance, here, in our planet.

Finally,  the star system broadcasted intelligent radio signal with 'news' that are already approximately 97.85 years old'.

6 0
3 years ago
What information is displayed in the message header of a received message? Check all that apply.
Aleks04 [339]

Answer:

the subject of the message

the sender's name

the recipient's name

the date and time when the message was received

Explanation:

Various information is displayed in the header of the message of a received message. And they are the subject of the message, which briefs what is there inside the message. And it mentions the sender's name as well as the recipient's name, and finally, the date and the time as well are stated that explains exactly when the message was being received. And all this information is shown in the header of the message.

3 0
4 years ago
Other questions:
  • Sasha has decided to start a consulting business. She will need space for large meetings and a receptionist. Which of the follow
    14·1 answer
  • Que es lo que me recomiendan estudiar? :v
    10·1 answer
  • What direction would you travel to go from japan to the united states
    14·1 answer
  • What type of IPv6 address should you use when you have multiple routers on a subnet and want hosts to use the nearest router for
    10·1 answer
  • Which describes a design theme in PowerPoint? a set of elements that unify the slides and complement the topic a printed handout
    11·2 answers
  • Websites whose URL’s contain tildes (~) are usually published by the government. TRUE or FALSE.
    8·2 answers
  • LAB: Even/odd values in an array
    9·2 answers
  • Rachel wants to copy eight rows of data from one spreadsheet to another. She opens the spreadsheet, highlights the appropriate d
    15·2 answers
  • Edhesive lesson practice 8.3, question 5
    10·1 answer
  • What Microsoft feature enables you to represent text as colorful visuals
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!