VUsolutions Transferred to AchiKhasi.com

From December 2011, this blog www.VUsolutions.blogspot.com is transferred to http://achikhasi.com/vu/ . So, you may visit http://achikhasi.com/vu/ for latest study related help.

Back to home VUsolutions

VUsolutions Fans Club [join us for MORE solutions]

VUsolutions on Facebook

CS201 Solution

Wednesday, June 17, 2009 Posted In Edit This
SOLUTION:

#include
#include
#include
using namespace std;
int main()
{char filename[30];
int num,i;
string name,classs,line;
ifstream input;
ofstream output;
cout<<"what is the name of the file you are using? ";
cin>>filename;
output.open(filename); //open file
if(output.fail())
{ cout<<"file did not open please check it ";
system("pause");
return 1;
}
output<<"Roll NO Student Name Class ";
cout<<"Enter Roll No ( <0 to exit): ";
cin>>num;
while(num>0)
{cin.ignore(255,' ');
cout<<"Enter name: ";
getline(cin,name);
cout<<"Enter class: ";
getline(cin,classs);
output<<" "<<<" "<<<" "<<
cout<<"Enter Roll No ( <0 to exit): ";
cin>>num;
}
output.close();
input.open(filename); //open file
if(input.fail())
{ cout<<"file did not open please check it ";
system("pause");
return 1;
}
cout<
while(input)
{getline(input,line);
cout<<
}
output.close();
system("pause");
return 0;
}

______________________________
2nd SOLUTION
______________________________

#include
#include
#include


int main(void)
{

char rollNo[10],studentName[20],studentClass[20];
ifstream iFile;
ofstream oFile;
oFile.open("Student_info.txt",ios::out);
iFile.open("Student_info.txt");
if (!iFile)
{
cout << "iFile could not be opend";
}

if (!oFile)
{
cout << "oFile could not be opened";
}

oFile << "RollNo" << "\t" << "StudentName" << "\t" << "Class" <oFile << "101" << "\t" << "AliRaza" << "\t" << "BS(CS)" <oFile << "102" << "\t" << "Usman" << "\t" << "MS(CS)" <oFile << "103" << "\t" << "Faizan" << "\t" << "BS(CS)" <oFile << "104" << "\t" << "Rehan" << "\t" << "MIT" <oFile << "105" << "\t" << "Ahmed" << "\t" << "MCS";
oFile.close();

while (!iFile.eof())
{
iFile >> rollNo >> studentName >> studentClass;
cout << rollNo << "\t"<< studentName << "\t"<<"\t"<
}
iFile.close();
system("PAUSE");
return 0;
}


www.VUsolutions.blogspot.com


[[NOTE:- We always try our best to upload 100% correct solution BUT it is requested that you kindly review it before submission, please.]]

_________________________________________



Problem Statement:

Writing and Reading student data in a file.

Detailed Description:
Write a program in which you have to:
1. Create a text file “Student_info”.

2. Using Code Write the following data in it:

Roll NO Student Name Class
101 Ali Raza BS(CS)
102 Usman MS(CS)
103 Faizan BS(CS)
104 Rehan MIT
105 Ahmed MCS


3. Open file and read data from it and display on the screen.

Sample Output
Student Information

Roll NO Student Name Class
101 Ali Raza BS(CS)
102 Usman MS(CS)
103 Faizan BS(CS)
104 Rehan MIT
105 Ahmed MCS

Deadline
Your assignment must be uploaded/submitted on or before 18-06-2009.

Back to home VUsolutions

Shaadi.com: Just create ur account & find ur partner or EARN money, its reall & EASY

VUsolutions Followers (Join NOW and Get Extra Benefits)

Install LATEST toolbar having lot of features - GET solutions on Desktop

toolbar powered by Conduit
Caliplus 300x250 NoFlam VitoLiv 468x60 GlucoLo