CJCoding With Joseph
15free / daySign inCreate account
TitleOpen
574
Read the First WordA text file contains words separated by spaces and newlines, for example: hello world Write a function string firstWord(const string& filename) that returns the first word of the file.
easyNot startedSolve
575
Read One Integer from a FileA text file starts with a whole number, for example: 42 Write a function int readNumber(const string& filename) that returns the first integer stored in the file.
easyNot startedSolve
576
Did the File Open?Write a function bool canOpen(const string& filename) that tries to open the file for reading and returns true if it opened successfully and false otherwise.
easyNot startedSolve
577
Count LinesA text file contains one item per line, for example: red green blue Write a function int countLines(const string& filename) that returns how many lines the file has.
easyNot startedSolve
578
Sum Numbers in a FileA text file contains whole numbers separated by spaces or newlines, for example: 10 20 30 Write a function int sumFile(const string& filename) that returns the sum of every number in the file.
easyNot startedSolve
579
Read the First LineWrite a function string firstLine(const string& filename) that returns the entire first line of the file, spaces included.
easyNot startedSolve
580
Print a FileWrite a function void printFile(const string& filename) that prints every line of the file to cout, in order, each followed by a newline.
easyNot startedSolve
581
Count WordsA text file contains words separated by any mix of spaces and newlines, possibly with extra blank space, for example: the quick brown fox jumps Write a function int countWords(const string& filename) that returns how many words the file contains; a word is any run of non-whitespace characters.
easyNot startedSolve
582
Read Mixed ValuesThe starter first writes the single line Alice 30 5.5 into person.txt (that part is done for you), then opens the file as ifstream in.
easyNot startedSolve
583
Close and ReportThe starter writes hello into notes.txt, opens it as ifstream in, reads one word and prints Read: hello.
easyNot startedSolve
598
Write One LineWrite a function void writeGreeting(const string& filename) that opens filename with an ofstream (the starter does this as out) and writes exactly one line: Hello, file!
easyNot startedSolve
599
Write Numbers 1 to 5Write a function void writeNumbers(const string& filename) that opens filename with an ofstream and writes the integers 1, 2, 3, 4 and 5, one number per line (each followed by a newline).
easyNot startedSolve
600
Write a Vector on One LineWrite a function void writeVector(const string& filename, const vector<int>& v) that opens filename with an ofstream and writes all the values of v on a single line, separated by single spaces, followed by one newline.
easyNot startedSolve
601
Check Open Before WritingWrite a function bool saveText(const string& filename, const string& text) that opens filename with an ofstream (the starter does this as out).
easyNot startedSolve
602
Append a LineWrite a function void appendLine(const string& filename, const string& line) that opens filename in append mode (ios::app) and writes line followed by a newline at the end of the file, keeping the existing contents.
easyNot startedSolve
603
Write Then Read BackThe program opens the file words.txt with an ofstream called out, closes it, then reopens the same file with an ifstream and prints every line it finds.
easyNot startedSolve
604
Save a PersonWrite a function void savePerson(const string& filename, const string& name, int age) that opens filename with an ofstream (the starter does this as out) and writes two lines: Name: followed by a space and the name, then Age: followed by a space and the age.
easyNot startedSolve
605
Overwrite an Existing FileWrite a function void overwrite(const string& filename, const string& text) that replaces whatever the file currently contains with a single line: text followed by a newline.
easyNot startedSolve
606
Close Before ReopeningThe program writes the line done to status.txt with an ofstream called out, then opens the same file with an ifstream and prints every line it contains.
easyNot startedSolve
607
Write a Formatted PriceWrite a function void writePrice(const string& filename, double p) that opens filename with an ofstream (the starter does this as out) and writes one line: Price: followed by a space and p shown with exactly two digits after the decimal point, then a newline.
easyNot startedSolve
622
Print to an ostream ParameterWrite a function void printHello(ostream& out) that writes the text Hello, stream!
easyNot startedSolve
623
Sum to a StreamWrite a function void printSum(ostream& out, int a, int b) that writes the equation a + b = sum to out, followed by a newline.
easyNot startedSolve
624
operator<< for a ColorA struct Rgb with three public ints r, g, b is given.
easyNot startedSolve
625
setw Right AlignmentThe variable int value = 42; is declared for you.
easyNot startedSolve
626
Zero Padding with setfillThe variable int id = 42; is declared for you.
easyNot startedSolve
627
Two Decimal PlacesThe variable double pi = 3.14159; is declared for you.
easyNot startedSolve
628
Left-Aligned ColumnThe variable string header = "Name"; is declared for you.
easyNot startedSolve
629
Return the Stream for ChainingWrite a function ostream& printPair(ostream& out, int a, int b) that writes (a, b) — an opening parenthesis, the first number, a comma and a space, the second number, a closing parenthesis — to out with NO newline, and then returns out.
easyNot startedSolve
630
cout Is an ostreamThe starter declares ostream& out = cout; and int total = 5;.
easyNot startedSolve
631
Print a Vector to a StreamWrite a function void printVec(ostream& out, const vector<int>& v) that writes the elements of v inside square brackets, separated by a comma and a space, followed by a newline.
easyNot startedSolve
646
fstream in Write ModeWrite a function void writeWithFstream(const string& filename, const string& text) that opens filename with an fstream in ios::out mode and writes text followed by a newline.
easyNot startedSolve
647
fstream in Read ModeWrite a function string readWithFstream(const string& filename) that opens filename with an fstream in ios::in mode, reads the first line with getline, and returns it (without the newline).
easyNot startedSolve
648
Append with fstreamWrite a function void appendFs(const string& filename, const string& line) that opens filename with an fstream in ios::out | ios::app mode and writes line followed by a newline.
easyNot startedSolve
649
in-and-out Needs an Existing FileWrite a function bool openReadWrite(const string& filename) that opens filename with an fstream in ios::in | ios::out mode and returns whether the open succeeded (the result of is_open()).
easyNot startedSolve
650
Write, Seek, ReadThe program below opens note.txt with an fstream in ios::in | ios::out | ios::trunc mode.
easyNot startedSolve
651
tellg After ReadingThe program below writes the eleven characters hello world (no newline) into words.txt, then opens it for reading with an fstream.
easyNot startedSolve
652
File Size with seekg/tellgWrite a function long fileSize(const string& filename) that opens filename with an fstream in ios::in | ios::binary mode (the open is already written for you), seeks to the end with seekg(0, ios::end), and returns tellg() cast to long.
easyNot startedSolve
653
Reset a File with ios::truncWrite a function void resetFile(const string& filename) that opens filename with an fstream in ios::out | ios::trunc mode and writes the single line reset (followed by a newline) to it.
easyNot startedSolve
654
Count Reads Until FailureThe program below writes 5 10 15 into numbers.txt and opens it for reading with an fstream.
easyNot startedSolve
655
Reuse One fstream ObjectThe program below opens data.txt for writing with an fstream, writes the number 42, and later reads a number back from the same stream object.
easyNot startedSolve
584
Largest Number in a FileA text file contains one or more integers separated by spaces or newlines, for example: 12 91 5 44 Write a function int maxInFile(const string& filename) that opens the file, reads every integer with >> and returns the largest one.
mediumNot startedSolve
585
Number Each LineWrite a function void printNumbered(const string& filename) that prints every line of the file preceded by its 1-based line number, a colon and one space.
mediumNot startedSolve
586
Line Containing a WordWrite a function int lineOf(const string& filename, const string& word) that returns the 1-based number of the first line of the file that contains word anywhere inside it, or -1 if no line contains it.
mediumNot startedSolve
587
Average with Missing-File BranchWrite a function void printAverage(const string& filename).
mediumNot startedSolve
588
Parse Name,Score LinesA file holds one record per line in the form name,score with no spaces around the comma: Bob,90 Amy,85 Write a function void printScores(const string& filename) that prints one line per record in the form <name> scored <score>, in file order, each ending with a newline (see Expected Output).
mediumNot startedSolve
589
Longest LineWrite a function string longestLine(const string& filename) that returns the line of the file with the most characters.
mediumNot startedSolve
590
Count a Character with getWrite a function int countChar(const string& filename, char c) that returns how many times the character c appears in the file.
mediumNot startedSolve
591
Read a Config ValueA configuration file holds one key=value pair per line with no spaces around the =: host=localhost port=8080 debug=true Write a function string getValue(const string& filename, const string& key) that returns the value whose key matches key exactly (the whole text before the =), or the string not found if no line has that key.
mediumNot startedSolve
592
Skip the Header LineThe first line of the file is a text header that must be skipped; every line after it holds integers separated by spaces or newlines: scores 20 25 30 Write a function int sumAfterHeader(const string& filename) that returns the sum of all the numbers after the header.
mediumNot startedSolve
593
Lines Containing TextWrite a function vector<string> linesContaining(const string& filename, const string& sub) that returns, in file order, every line that contains sub as a substring.
mediumNot startedSolve
608
Squares TableWrite a function void writeSquares(const string& filename, int n) that opens filename with an ofstream and writes one line for every integer k from 1 to n (n is always at least 1).
mediumNot startedSolve
609
Write Only EvensWrite a function int writeEvens(const string& filename, const vector<int>& v) that opens filename with an ofstream and writes only the even values of v, in their original order, on a single line separated by single spaces, with no space before the first value, followed by one newline.
mediumNot startedSolve
610
Copy a FileWrite a function bool copyFile(const string& src, const string& dst) that copies a text file line by line.
mediumNot startedSolve
611
Event LogWrite a function void logEvent(const string& filename, const string& msg) that opens the log file in append mode and adds one line at the end without erasing the lines already there: LOG: followed by a space and msg, then a newline.
mediumNot startedSolve
612
Save stdin UppercasedRead every line from standard input until the input ends, convert each line to uppercase, and write the uppercased lines to the file input_copy.txt (create or truncate it; one line per input line, each followed by a newline).
mediumNot startedSolve
613
Aligned Table to FileWrite a function void writeTable(const string& filename, const vector<pair<string, int>>& rows) that opens filename with an ofstream and writes one line per row: the name left-aligned in a field 8 characters wide (left, setw(8)), immediately followed by the quantity right-aligned in a field 4 characters wide (right, setw(4)), then a newline.
mediumNot startedSolve
614
Write CSVWrite a function void writeCsv(const string& filename, const vector<string>& names, const vector<int>& scores) that opens filename with an ofstream and writes one line per index i: names[i], a comma (no spaces around it), scores[i], then a newline.
mediumNot startedSolve
615
Receipt with TotalWrite a function void writeReceipt(const string& filename, const vector<double>& prices) that opens filename with an ofstream and writes one line per price, numbered from 1, in the form Item 1: 3.50.
mediumNot startedSolve
616
Truncate or AppendWrite a function void save(const string& filename, const string& text, bool append) that writes text followed by a newline to filename.
mediumNot startedSolve
617
Multiplication Grid to a FileWrite a function void writeGrid(const string& filename, int n) that opens filename with an ofstream and writes an n by n multiplication table.
mediumNot startedSolve
632
operator<< for MoneyA class Money that stores a whole number of cents is given, together with a friend declaration for operator<<.
mediumNot startedSolve
633
Table Row HelperWrite a function void printRow(ostream& out, const string& name, int qty, double price) that writes one table row to out and ends it with a newline.
mediumNot startedSolve
634
Polymorphic print(ostream&)An abstract base class Shape is given in the starter with the pure virtual method virtual void print(ostream& out) const = 0;.
mediumNot startedSolve
635
Percent FormatterWrite a function void printPercent(ostream& out, double ratio) that takes a ratio between 0 and 1, multiplies it by 100, and writes the result to out with exactly one decimal place, immediately followed by a % sign and a newline.
mediumNot startedSolve
636
operator<< for PlaylistA class Playlist holding a vector<string> of song names is given, together with a friend declaration for operator<<.
mediumNot startedSolve
637
Receipt to Any StreamWrite a function void receipt(ostream& out, const vector<pair<string, double>>& items) that writes one line per item — the item name, a single space, and the price with exactly 2 decimal places — and then a final line Total: followed by the sum of all prices, also with 2 decimals.
mediumNot startedSolve
638
Chainable BannerWrite a function ostream& banner(ostream& out, const string& title) that writes three equals signs, a space, the title, a space, and three equals signs (=== title ===) to out with NO newline, and returns out.
mediumNot startedSolve
639
Hex and DecimalWrite a function void printHexDec(ostream& out, int n) that writes n in decimal, then a space, an equals sign, a space and 0x, then n again in lowercase hexadecimal (no padding), then a newline — for 255 the line is 255 = 0xff, for 0 it is 0 = 0x0.
mediumNot startedSolve
640
boolalpha FlagsWrite a function void printFlags(ostream& out, bool a, bool b) that writes a= followed by the first flag, a space, b= followed by the second flag, and a newline — with the flags printed as the words true / false.
mediumNot startedSolve
641
Matrix to StreamWrite a function void printMatrix(ostream& out, const vector<vector<int>>& m) that writes each row of the matrix on its own line, with every value right-aligned in a field 4 characters wide (padded with spaces on the left) and nothing else between values.
mediumNot startedSolve
656
Write Then Read in One ObjectWrite a function int writeAndSum(const string& filename, const vector<int>& v) that uses ONE fstream object for both directions: 1.
mediumNot startedSolve
657
Append Then Count LinesWrite a function int appendAndCount(const string& filename, const string& line) that: 1.
mediumNot startedSolve
658
Persistent CounterWrite a function int incrementCounter(const string& filename) that: 1.
mediumNot startedSolve
659
Replace a WordWrite a function int replaceWord(const string& filename, const string& from, const string& to) that replaces every whole word equal to from with to inside a text file and returns how many words were replaced.
mediumNot startedSolve
660
Read the Nth Fixed RecordWrite a function string nthRecord(const string& filename, int n) that opens filename with an fstream in ios::in | ios::binary mode, seeks the read position to byte n 4, reads that one record with getline, and returns the three letters (without the newline).
mediumNot startedSolve
661
Numbered AppendWrite a function void appendNumbered(const string& filename, const string& msg) that appends a numbered line: the number is one more than the number of lines the file already contains, so the first message becomes 1.
mediumNot startedSolve
662
Capitalize the First CharacterWrite a function void capitalizeFirst(const string& filename) that opens filename with an fstream in ios::in | ios::out mode, reads its first character with get, moves the write position back to the start with seekp(0), and writes the uppercase version of that character (use toupper from <cctype>) over it with put.
mediumNot startedSolve
663
Notes from stdinWrite a program that reads lines from standard input until the input ends, stores them in a file, then reads the file back through the same fstream object and prints the numbered notes.
mediumNot startedSolve
664
Strip Blank LinesWrite a function int stripBlankLines(const string& filename) that removes every blank line from a text file and returns how many lines were removed.
mediumNot startedSolve
665
Reverse Lines in PlaceWrite a function void reverseLines(const string& filename) that reverses the order of the lines in a text file: the last line becomes the first, and so on.
mediumNot startedSolve
724
Ticket Line That Leaves the Stream UntouchedTicket is written for you, with a friend declaration for operator<<.
mediumNot startedSolve
725
Receipts Numbered by a Static CounterReceipt is written for you with a friend declaration.
mediumNot startedSolve
594
Grade Book ReportWrite a function void gradeReport(const string& filename).
hardNot startedSolve
595
Transpose a Matrix FileThe first line of the file holds two integers R C: the number of rows and the number of columns.
hardNot startedSolve
596
Log Reader ClassCreate a class LogReader that loads a log file in its constructor.
hardNot startedSolve
597
First Differing LineWrite a function int firstDifference(const string& a, const string& b) that compares two text files line by line and returns the 1-based number of the first line where they differ, or 0 if the files are identical.
hardNot startedSolve
618
Rotating LoggerCreate a class Logger that writes log lines to a file but never lets the file grow beyond a limit.
hardNot startedSolve
619
Split by ParityWrite a function void splitByParity(const string& src, const string& evens, const string& odds) that reads all the whitespace-separated integers from the file src and writes every even integer to the file evens and every odd integer to the file odds, in the order they were read.
hardNot startedSolve
620
High Scores Save and LoadCreate a class HighScores that keeps a list of (name, score) entries.
hardNot startedSolve
621
Word Counts to FileWrite a function void writeWordCounts(const string& src, const string& dst) that reads every whitespace-separated word from the file src, counts how many times each word appears, and writes the result to the file dst (created or truncated): one line per distinct word, in alphabetical order, as the word, a space, its count, then a newline.
hardNot startedSolve
642
Inventory Report operator<<Build a class Inventory: 1.
hardNot startedSolve
643
Polymorphic Employee ReportThe starter gives an abstract base class Employee: a protected name, the constructor Employee(const string& name), and virtual void describe(ostream& out) const = 0;.
hardNot startedSolve
644
Indented Tree PrinterBuild a class Node representing one node of a tree: 1.
hardNot startedSolve
645
Restore Stream StateWrite a function void printMoney(ostream& out, double v) that writes a dollar sign followed by v with exactly two decimals and a newline ($1234.50 for 1234.5), then leaves out in exactly the state it found it.
hardNot startedSolve
666
File-Backed Key-Value StoreBuild a class KVStore that keeps string keys and values in a text file: one entry per line as the key, a space, the value (e.g.
hardNot startedSolve
667
Fixed-Width Record EditorBuild a class RecordFile that stores names in a binary file as fixed-width records of exactly 8 bytes, no separators.
hardNot startedSolve
668
Bank Ledger FileBuild a class Ledger that records bank transactions in a text file and recomputes the balance from that file every time it is asked — nothing is cached.
hardNot startedSolve
669
Merge Two Files UniquelyWrite a function int mergeUnique(const string& a, const string& b, const string& out) that reads two text files and writes a third one containing every distinct line from either input, sorted in ascending (dictionary) order, one per line, each followed by a newline.
hardNot startedSolve