Question

In: Computer Science

Name your c++ file Word_LastNameFirstName.cpp. Create a struct that has a word and the length of...

Name your c++ file Word_LastNameFirstName.cpp. Create a struct that has a word and the length of the word. Next, use the struct to store the word read from a text file call “word.txt” and the length of the word. Print out the word x number of times based on the length of the word as shown below. Also, print a statement with the length and determine if the string length has an odd number or even number of characters. You need to create your own text file and place in the proper folder.

For instance, if the file contains the string "Program", its length is 7, 7 is a odd number and it will be printed 7 times like the below. Print to the console like below

OUTPUT :     

Program

Program

Program

Program

Program

Program

Program

The word "Program" has a length of 7 and has an odd number of character

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// word.txt

Program

______________________

#include <iostream>

#include <iomanip>

#include <fstream>


using namespace std;

//Create Struct Word
struct Word
{
//Declaring variables
string word;
int length;  
};
int main() {
   //Declaring variables
   string word;
   ifstream dataIn;
  
   //Open the input file
   dataIn.open("word.txt");
   //checking whether the file name is valid or not
if(dataIn.fail())
{
   cout<<"** File Not Found **";
return 1;
}
else
{
   //Reading the word from the input file
   dataIn>>word;
  
   //Creating the instance of struct Word
   struct Word wd;
   wd.word=word;
   wd.length=word.length();
dataIn.close();
     
for(int i=0;i<wd.length;i++)
   {
       cout<<wd.word<<endl;
   }    
   cout<<"The word \""<<wd.word<<"\" has a length of "<<wd.length<<" and has an ";
   if(wd.length%2==0)
   {
   cout<<"even";  
   }
   else
   {
   cout<<"odd";      
   }
  
   cout<<" number of character"<<endl;
}

return 0;
}

____________________________

output:

_______________Could you plz rate me well.Thank You


Related Solutions

HW_6d - Write a struct object to a binary file. Create a new C++ project and...
HW_6d - Write a struct object to a binary file. Create a new C++ project and name it as:   Cats Create a Source.cpp file. Declare a struct named Cat. (in the Source.cpp file, or in a separate header file) Each Cat object has a name and age. The name data member is a c_string. The age data member is an integer. Ask the user to enter 3 cats. Use a while loop to read the information about one cat entered...
Create a Word file containing the following: The full name of the “test subject” The test...
Create a Word file containing the following: The full name of the “test subject” The test subject is a person, not yourself, who can say the names of the products. The best test subject is one who is adamant about being an expert who can distinguish brand A from B. You cannot be the test subject because you generate the sequence, and the test subject cannot see it for an unbiased test. Pets and babies are not allowed as they...
Create a structure in C called BarcelonaPlayer with the following members. struct BarcelonaPlayer { char name[20];...
Create a structure in C called BarcelonaPlayer with the following members. struct BarcelonaPlayer { char name[20]; int age; char country[20]; char Position[20]; double Salary; double Rating; }; First, create an array of BarcelonaPlayer structures. Now, write a function that takes an array of BarcelonaPlayer structures as input and find out the highest paid player among all the players. void highestPaidPlayer(struct BarcelonaPlayer *pl, int size); Create another function that finds all the players from Argentina. void findPlayers(struct BarcelonaPlayer *pl, int size);
(C++) Create a data file and name it "input.txt". manually save 10 integers into the file....
(C++) Create a data file and name it "input.txt". manually save 10 integers into the file. Write a program to read the data and calculate the average of events and odds, separately. Print out the average values.
Create a C program that solves the word search puzzle contained in the file 'WordSearchPuzzle.txt'. The...
Create a C program that solves the word search puzzle contained in the file 'WordSearchPuzzle.txt'. The words that need to be found are in the file 'WordList.txt'. There are 100 words to be found. You must find the location of the first and last letter of each word as well as the cardinal direction that describes the word's orientation. The location of first and last letters are to be described in terms of row and column, with indexing starting at...
HW_6a - Read a text file Create a new C++ project and name it as:   Numbers...
HW_6a - Read a text file Create a new C++ project and name it as:   Numbers Create a text file and     save it as:   data.txt Create and save the file      in a C++ project      in the Resource folder. Enter the following numbers:        3                                                              4                                                              5       Note:   After you enter the 5, don’t press the enter key. Save and close the file. Add another file and name it:   Source.cpp Write one statement that declares a file...
Create a struct MenuItem containing fields for name (a string) and price (a float) of a...
Create a struct MenuItem containing fields for name (a string) and price (a float) of a menu item for a diner. Create a ReadItem() function that takes an istream and a MenuItem (both by reference) and prompts the user for the fields of the MenuItem, loading the values into the struct's fields. Create a PrintItem() function that takes an output stream (by reference) and a MenuItem (by value) and prints the MenuItem fields to the stream in a reasonable one-line...
Name your file “DMx1_Your last name_Your first name.” You can use MS Word to complete the...
Name your file “DMx1_Your last name_Your first name.” You can use MS Word to complete the matrices (go to Insert, Table, Insert table, fill the table). Save the file as a PDF file. If you draw the matrices on paper, take pictures. Make sure the pictures are clear and readable. Insert the pictures in MS Word document and save it as a PDF file. 1. Align using dot matrix: horizontal sequence – AGGCTCCC, vertical sequence – GCGCTCCG. Trace and explain...
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT