Write a C++ Program
Consider the following incomplete C++ program:
#include <iostream>
using namespace std;
int main()
{
….
}
Rewrite the program include the following statements.
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
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
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..
Get Answers For Free
Most questions answered within 1 hours.