Question

Write a C++ Program Consider the following incomplete C++ program: #include <iostream> using namespace std; int...

Write a C++ Program

Consider the following incomplete C++ program:

#include <iostream>

using namespace std;

int main()

{

   ….

}

Rewrite the program include the following statements.

  • Include the header file fstream, string, and iomanip in this program.
  • Declare inFile to be an ifstream variable and outFile to be an ofstream variable.
  • The program will read data from the file inData.txt and write output to the file outData.txt. Include statements to open both of these files, associate inFile with inData.txt, and associate outFile with outData.txt

By using your Notepad, construct the file inData.txt to contain the following data:

10.20 5.35

15.6

Randy Gill 31

18500 3.5

A

  • The numbers in the first line represent the length and width of a rectangle. The number in the second line represents the radius of a circle. The third line contains the first name, last name, and the age of a person. The fourth line contains saving balance and the interest rate per year. The fifth line contain a capital letter A. Write a program statement so that after the program execute, the program generates the content of the outData.txt are shown as below.

Rectangle:

Length = 10.20, width = 5.35

Radius = 15.6

Name: Rand Gill, Age = 31

Balance = $18,553, Interest Rate = 3.50

Character = A

You must insert the following comments at the beginning of your program and write our commands in the middle:

Write a C++ Program:


/*

// Name: Your Name

// ID: Your ID

*/

#include <iostream>

using namespace std;

int main()

{
         YOUR CODE HERE

Homework Answers

Answer #1

I have written the program using CPP PROGRAMMING LANGUAGE.

INPUT :

OUTPUT :

CODE :

/*

// Name: Your Name

// ID: Your ID

*/

//Included the required libraries

#include <iostream>

#include <bits/stdc++.h>

#include <vector>

using namespace std;

//main method

int main() {

// filestream variable file

fstream file;

ofstream myfileout;

string word, t, q, filename;

vector<string> data;//to store the data of input file

// filename of the input file

filename = "inData.txt";

// opening file

file.open(filename.c_str());

// extracting words from the file

while (file >> word)

{

// adding all the strings to the vector

data.push_back(word);

}

file.close();//closing the input file

//created the output file

myfileout.open ("outData.txt");

//Writting to output file

cout << "Created the OUTPUT file Successfully"<<endl;

myfileout<< "Rectangle:\nLength = "<<data[0]<<", width = "<<data[1]<<endl<<"Radius = "<<data[2]<<endl<<"Name: "<<data[3]<<" "<<data[4]<<", Age = "<<data[5]<<endl<<"Balance = "<<data[6]<<", Interest Rate = "<<data[7]<<endl<<"Character = "<<data[8];

myfileout.close();//To close the output file

return 0;

}

Thanks..

Know the answer?
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
Similar Questions
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } _______________ #include <iostream> using namespace std; int main() { int i,j; for (i=1; i<=3; i++) { for(j=1; j<=i; j++ ) { cout<<"*"; } cout << "\n";   } return 0; }
C ++ #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile;...
C ++ #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile; inFile.open("bmi.txt"); while (!inFile.eof()) { inFile >> bmi; if( bmi < 18.5) { cout << bmi << " is underweight " ; } else if( bmi >= 18.5 && bmi <= 24.9) { cout << bmi << " is in normal range " ; } else if( bmi >= 25.0 && bmi <= 29.9) { cout << bmi << " is overweight " ; }...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void modifyArray( int [ ], int );    void modifyElement ( int );      int main( ) {   const int arraySize = 8;   int a[arraySize] = { 2, -2, 10, -3, -1 ,0, 10, -5 };      modifyArray ( a, arraySize);      for ( int i =0; i < arraySize; i++)               cout << a[i] << ‘  ’;         modifyElement ( a[4] );          for ( int i =0; i <...
What is value ofmyInt? #include <iostream> using namespace std; int main() {    int myInt;   ...
What is value ofmyInt? #include <iostream> using namespace std; int main() {    int myInt;    int* myScore;    int myVar;       myInt = 10;    myScore = &myInt;    myVar = 20;    myVar = *myScore;    *myScore = 30;    myVar = 40;    myVar = *myScore;    } Group of answer choices 30 20 10 0
complete the following tasks in C++ code: #include <iostream> using namespace std; class Cube{ public: Cube(int,...
complete the following tasks in C++ code: #include <iostream> using namespace std; class Cube{ public: Cube(int, int,int); int getVolume(); private: int height; int weight; int depth; }; Cube::Cube(int h, int w, int l) { height = h; weight = w; depth = l; } int main(){ }
C++ question. Must use #include <iostream> and "using namespace std;" You must also have only a...
C++ question. Must use #include <iostream> and "using namespace std;" You must also have only a .cpp and .h file Define a class called Rectangle that can store the height and width of a rectangle as instance variables, has a constructor that allows you to set the height and width when you create a Rectangle, a default constructor that sets both height and width to 0, and functions to return the following values: * the perimeter [ which should be...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std;...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std; int main() {        int x;        cout << "Selection option " << endl;        cin >> x;        if (x == 1)               cout << "You select option 1" << endl;        else if (x >= 2 || x <= 4)               cout << "You select options 2 or 3 or 4" << endl;               else if (x == 10)               cout << "You select option 10" << endl;               else...
/* Displaying process segment addresses */ #include <iostream> extern int etext, edata, end; using namespace std;...
/* Displaying process segment addresses */ #include <iostream> extern int etext, edata, end; using namespace std; int main( ){ cout << "Adr etext: " << hex << int(&etext) << "\t "; cout << "Adr edata: " << hex << int(&edata) << "\t "; cout << "Adr end: " << hex << int(&end ) << "\n"; return 0; } please modify this above code and execute to get the output.
Write up to three lines to explain the logic used behind those codes.        1) #include <iostream>...
Write up to three lines to explain the logic used behind those codes.        1) #include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {         ifstream infile("worldpop.txt");         vector<pair<string, int>> population_directory;         string line;         while(getline(infile, line)){                 if(line.size()>0){                         stringstream ss(line);                         string country;                         int population;                         ss>>country;                         ss>>population;                         population_directory.push_back(make_pair(country, population));                 }         }         cout<<"Task 1"<<endl;         cout<<"Names of countries with population>=1000,000,000"<<endl;         for(int i=0;i<population_directory.size();i++){                 if(population_directory[i].second>=1000000000){                        ...
#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout...
#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout << "Welcome to the Calorie Count-ulator!\n"; // Get user input: cout << "Enter your meal choice ([P]izza, [S]alad, [H]amburger)\n"; cin >> meal_choice; cout << "Enter the amount of servings (1-9):\n"; cin >> servings; // TODO: Use a switch statement to evaluate the user's meal choice // Handle error checking where appropriate // Exit the program: return 0;}
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT