Answer to Question #22723 in C++ for kirubel

Question #22723
1. Write a c++ code that saves strings from the "names" array into a text(.txt) file in ascending alphabetical order.
Finally the program should display everything saved in the text file back into the command line. Every full
name must start in a new line. Your code must declare at least one function other than the main.
1
Expert's answer
2013-01-24T08:05:14-0500
#include <fstream>
#include <string>
#include<iostream>

using namespace std;
&
int main (){
string s[6],q;
s[0]="qwerty";
s[1]="wqwerty";
s[2]="aqwerty";
s[3]="cwerty";
s[4]="fqwerty";
s[5]="xqwerty";
& for(int w=0; w<5; w++){
for(int i=0; i<5; i++){
if(s[i][0]>s[i+1][0]){
q=s[i];
s[i]=s[i+1];
s[i+1]=q;

}

}
w++;
}

for(int i=0; i<5; i++){
cout<<s[i]<<"\n";
}

ofstream f("cars.txt",ios::app);
& for(int i=0; i<5; i++){
f<<s[i]<<"\n";
}
&
system("PAUSE"); &
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS