please use C programming 1 File HEAD program Write a program
please use C++ programming
1. File \"HEAD\" program:
Write a program that asks the user for the name of a file. The program shold display the first 10 lines of the file on the screen (the \"head\" of the file). If the file has fewer than 10 lines, the entire file should be displayed, with a message indicating the entire file has been displayed.
2. File Display Program.
Write a program that asks the user for the name of a file. The program should display the contents of the file on the screen. If the file\'s contents won\'t fit on a single screen, the program should display 24 lines of output at a time, and then pause. Each time the program pauses it should wait for the user to strike a key before the next 24 lines are displayed.
3. Data Conversion Program
Write a program that reads data from a file, performs a units conversion, and writes the data to a new file. Offer the user the following choices of conversions: degrees F to degrees C, degrees C to degrees F, feet to meters, meters to feet, ounces to grams, grams to ounces. In the new file, the first line of the file should indicate the original units and the altered units, and the next lines should have both the input and the converted data. For example:
INPUT:
OUTPUT:
| 32.0 |
| 0 |
| 72 |
Solution
1)solution
#include <fstream>
#include <string>
#include<iostream>
using namespace std;
int main () {
string sentence;
ifstream myfilename (\"D:\\\\example.txt\");
if (myfilename.is_open())
{
int count=0;
while ( getline (myfilename,sentence) )
{
++count;
if(count<=10)
{
cout << sentence << \'\ \';
}else
break;
}
if(count<10)
{
cout<<\"entire file is read\"<<endl;
}
myfilename.close();
}
else
cout << \"Unable to open file\";
return 0;
}
output
the log value of 6 is 0
the nlogn value of 6 is 0
the h(n) value of 1 is 1
the p(n) value of 6 is 1
the q(n) value of 1 is 1
entire file is read
2)solution
#include <fstream>
#include <string>
#include<iostream>
using namespace std;
int main () {
string sentence;
ifstream myfilename (\"D:\\\\example.txt\");
if (myfilename.is_open())
{
int count=0;
while ( getline (myfilename,sentence) )
{
++count;
if(count<=24)
{
cout << sentence << \'\ \';
}else
{
string key;
cout<<\"enter a key for read another lines\"<<endl;
cin>>key;
count=0;
}
}
if(count<24)
{
cout<<\"entire file is read\"<<endl;
}
myfilename.close();
}
else
cout << \"Unable to open file\";
return 0;
}
output
the log value of 6 is 0
the nlogn value of 6 is 0
the h(n) value of 1 is 1
the p(n) value of 6 is 1
the q(n) value of 1 is 1
the exp(n) value of 1 is 2.71828
the exp(n) value of 1 is 1
the log value of 6 is 0.693147
the nlogn value of 6 is 1.38629
the h(n) value of 2 is 2
the p(n) value of 6 is 4
the q(n) value of 2 is 8
the exp(n) value of 2 is 7.38906
the exp(n) value of 2 is 2
the log value of 6 is 1.09861
the nlogn value of 6 is 3.29584
the h(n) value of 3 is 3
the p(n) value of 6 is 9
the q(n) value of 3 is 27
the exp(n) value of 3 is 20.0855
the exp(n) value of 3 is 6
the log value of 6 is 1.38629
the nlogn value of 6 is 5.54518
the h(n) value of 4 is 4
enter a key for read another lines
hjk
the q(n) value of 4 is 64
the exp(n) value of 4 is 54.5982
the exp(n) value of 4 is 24
the log value of 6 is 1.60944
the nlogn value of 6 is 8.04719
the h(n) value of 5 is 5
the p(n) value of 6 is 25
the q(n) value of 5 is 125
the exp(n) value of 5 is 148.413
the exp(n) value of 5 is 120the log value of 6 is 0
the nlogn value of 6 is 0
the h(n) value of 1 is 1
the p(n) value of 6 is 1
the q(n) value of 1 is 1
the exp(n) value of 1 is 2.71828
the exp(n) value of 1 is 1
the log value of 6 is 0.693147
the nlogn value of 6 is 1.38629
the h(n) value of 2 is 2
the p(n) value of 6 is 4
the q(n) value of 2 is 8
the exp(n) value of 2 is 7.38906
the exp(n) value of 2 is 2
the log value of 6 is 1.09861
enter a key for read another lines
jhk
the h(n) value of 3 is 3
the p(n) value of 6 is 9
the q(n) value of 3 is 27
the exp(n) value of 3 is 20.0855
the exp(n) value of 3 is 6
the log value of 6 is 1.38629
the nlogn value of 6 is 5.54518
the h(n) value of 4 is 4
the p(n) value of 6 is 16
the q(n) value of 4 is 64
the exp(n) value of 4 is 54.5982
the exp(n) value of 4 is 24
the log value of 6 is 1.60944
the nlogn value of 6 is 8.04719
the h(n) value of 5 is 5
the p(n) value of 6 is 25
the q(n) value of 5 is 125
the exp(n) value of 5 is 148.413
the exp(n) value of 5 is 120
the log value of 6 is 0
the nlogn value of 6 is 0
the h(n) value of 1 is 1
the p(n) value of 6 is 1
the q(n) value of 1 is 1
enter a key for read another lines
hj
the exp(n) value of 1 is 1
the log value of 6 is 0.693147
the nlogn value of 6 is 1.38629
the h(n) value of 2 is 2
the p(n) value of 6 is 4
the q(n) value of 2 is 8
the exp(n) value of 2 is 7.38906
the exp(n) value of 2 is 2
the log value of 6 is 1.09861
the nlogn value of 6 is 3.29584
the h(n) value of 3 is 3
the p(n) value of 6 is 9
the q(n) value of 3 is 27
the exp(n) value of 3 is 20.0855
the exp(n) value of 3 is 6
the log value of 6 is 1.38629
the nlogn value of 6 is 5.54518
the h(n) value of 4 is 4
the p(n) value of 6 is 16
the q(n) value of 4 is 64
the exp(n) value of 4 is 54.5982
the exp(n) value of 4 is 24
the log value of 6 is 1.60944
the nlogn value of 6 is 8.04719
enter a key for read another lines
hjk
the p(n) value of 6 is 25
the q(n) value of 5 is 125
the exp(n) value of 5 is 148.413
the exp(n) value of 5 is 120
entire file is read
--------------------------------
Process exited after 13 seconds with return value 0
Press any key to continue . . .



