View previous topic :: View next topic |
Author |
Message |
SnowWolf Advanced Cheater
Reputation: 0
Joined: 13 May 2007 Posts: 53
|
Posted: Sat Dec 01, 2007 2:13 am Post subject: [C++] output text file problem |
|
|
i have a problem of getting the file to output txt file, it doesn't change
just wanted to know what command should i use?
btw, i using vb6
i try different method uch as struct/void before but got error something like "old list statement?"
Code: |
////this script is make by myself not copy and paste.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int nsize = 20, fsize = 20;
int main()
{
fstream inoutf;
char filename[fsize];
char name[nsize], grade;
double emark, pmark, cmark, average;
cout<<"Please input the following file name (abc.txt)\n";
cout<<"that are using for this assignment.\n";
cout<<"\nEnter File Name : ";
cin>>filename;
inoutf.open(filename, ios::in | ios::out);
if (!inoutf)
{
cout<<"File not found! Whether file not exist or corrupted.\n";
cout<<"Program aborted.\n";
return 0;
}
cout<<"NAME\t\tGrade\t Mark\n";
cout<<"======\t\t===== ====="<<endl;
while(inoutf>>name>>emark>>pmark>>cmark)
{
average=(emark*7/10)+(pmark*15/100)+(emark*15/100);
if(average>=70)
grade='A';
else if(average>=59)
grade='B';
else if(average>=40)
grade='C';
else if(average>=35)
grade='D';
else
grade='F';
cout<<setprecision(3);
cout<<name<<"\t "<<average<<setw(8)<<grade<<endl;
}
inoutf.close();
return 0;
}
|
Quote: |
input :abc.txt
AlexChong
80 65 72
EricLeong
51 61 50
TonyEdward
49 54 52
output:abc.txt
Name grade mark
==== ==== ====
AlexChong 77.8 A
EricLeong 52.5 C
TonyEdward 49.8 C
|
make a mistake while typing.....
i wan my output text file shown like this. try .write before but failed
_________________
|
|
Back to top |
|
 |
Robotex Master Cheater
Reputation: 0
Joined: 05 Sep 2006 Posts: 378 Location: The pizza country!
|
Posted: Sat Dec 01, 2007 3:16 am Post subject: |
|
|
use tabs \t like you did
_________________
ASM/C++ Coder
Project Speranza lead developer |
|
Back to top |
|
 |
SnowWolf Advanced Cheater
Reputation: 0
Joined: 13 May 2007 Posts: 53
|
Posted: Sat Dec 01, 2007 4:00 am Post subject: |
|
|
no, what i mean the output text file should be shown as the same as the dos that i put white box.
but i only get the output text file that i get is same as previous1
Quote: |
example:
input (abc.txt)
abc
12 23 24
bcc
12 23 45
ddd
56 67 78
but the
output test file i get still same(abc.txt)
abc
12 23 24
bcc
12 23 45
ddd
56 67 78
the output text file i expect is like this (abc.txt)
Name Grade Mark
==== ===== ====
abc 15.5 F
bcc 18.6 F
ddd 61.0 B
|
_________________
|
|
Back to top |
|
 |
Robotex Master Cheater
Reputation: 0
Joined: 05 Sep 2006 Posts: 378 Location: The pizza country!
|
Posted: Sat Dec 01, 2007 4:23 am Post subject: |
|
|
Code: |
////this script is make by myself not copy and paste.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int nsize = 20, fsize = 20;
int main()
{
fstream inoutf;
char filename[fsize];
char name[nsize], grade;
double emark, pmark, cmark, average;
cout<<"Please input the following file name (abc.txt)\n";
cout<<"that are using for this assignment.\n";
cout<<"\nEnter File Name : ";
cin>>filename;
inoutf.open(filename, ios::in | ios::out);
if (!inoutf)
{
cout<<"File not found! Whether file not exist or corrupted.\n";
cout<<"Program aborted.\n";
return 0;
}
cout<<"NAME\t\tGrade\t Mark\n";
cout<<"======\t\t===== ====="<<endl;
inoutf<<"NAME\t\tGrade\t Mark\n";
inoutf<<"======\t\t===== ====="<<endl;
while(inoutf>>name>>emark>>pmark>>cmark)
{
average=(emark*7/10)+(pmark*15/100)+(emark*15/100);
if(average>=70)
grade='A';
else if(average>=59)
grade='B';
else if(average>=40)
grade='C';
else if(average>=35)
grade='D';
else
grade='F';
cout<<setprecision(3);
inoutf<<setprecision(3);
cout<<name<<"\t "<<average<<setw(8)<<grade<<endl;
inoutf<<name<<"\t "<<average<<setw(8)<<grade<<endl;
}
inoutf.close();
return 0;
} |
_________________
ASM/C++ Coder
Project Speranza lead developer |
|
Back to top |
|
 |
SnowWolf Advanced Cheater
Reputation: 0
Joined: 13 May 2007 Posts: 53
|
Posted: Sat Dec 01, 2007 4:43 am Post subject: |
|
|
ty
although still got a bit problem, i will try to solve myself
_________________
|
|
Back to top |
|
 |
|