Cout wordsu endl added endl for output return 0 void

  • No School
  • AA 1
  • 8

This preview shows page 5 - 8 out of 8 pages.

cout << words[u] << endl; //Added endl for output } return 0; } void sort(char a[]) //Changed parameters { // Sorting strings using bubble sort for (int i = MAX - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (a[j] > a[j + 1]) { Char temp = a[j + 1]; //Changed to string a[j + 1] = a[j]; a[j] = temp; } } } } //Added this thing right here
Image of page 5

Subscribe to view the full document.

//Q12 /*Code a program that will take a random line of text from an input file and display it to the screen. Make sure to make it so that your program generates a different number each time. Uses files, random, and strings.*/ #include <iostream> #include <iomanip> #include <string> #include <cmath> #include <cstdlib> #include <ctime> #include <fstream> using namespace std; //This will be the maximum number of lines the file can have const int MAX = 100; int main() { //random seed srand(time(NULL)); //create variables string surpriseme[MAX]; //X will hold how many lines there are in the file int x = 0; //i will hold which index we want to read int i; //open file ifstream inStream("random.txt"); //If file fails to open if (inStream.fail()) { cout << "File failed to open. \n"; exit(1); } else { //checks to see if file ends while (!inStream.eof()) { //gets one word at a time getline(inStream, surpriseme[x]); //displays to the screen cout << surpriseme[x] << endl; //Incrementing x by 1 x++;
Image of page 6
} //random generator from 0 to however many lines were in the file i = rand() % x; //displays the random word cout << endl << "Random word: " << surpriseme[i] << endl; } inStream.close(); return 0; } //Q14 /*Code a program that will pass text from an input file to an output file, not including a letter picked by the user (for example, ‘Hello there,’ could become ‘ello tere’ or ‘Hllo thr’). Uses files, strings, and arrays.*/ #include<iostream> #include<fstream>
Image of page 7

Subscribe to view the full document.

Image of page 8
  • Fall '19
  • Void type, Carriage return

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes