Description
PS6-1 Case-insensitive word search (ps6-1.cpp) [50 points]
Write a C++ program (ps6-1.cpp) that takes a file name and a keyword as input from the console
window and finds how many times the word appears in the file. Your program needs to prompt for the
file name first, and then prompt for the keyword. Your console window needs to look like:
Enter file name>C:/Users/soji/sampleText/text.txt
Enter keyword>Word
Use fgets from stdin or std::getline to take file name and keyword as input. (Make sure to remove
control code at the end of line if you use fgets as demonstrated in class. Otherwise your program won’t
find the file.)
Your program then opens the given file, and search for the keyword. When the program finds a
keyword, it needs to print the line number and the content of the line. Also your program needs to
count the occurrence of the word, and print how many times the keyword is included in the text file.
To make it easier, if the keyword is “the”, you can count “there” or “breathe” as one occurrence. Also,
you can assume that one line is less than 256 characters long. (If a matching word span across the 256-
character boundary, your program doesn’t have to find the word.)
Your search must be case-insensitive. So, if the user enters the keyword “the”, it must match all of “the”,
“The”, “tHe”, “THe”, “thE”, “ThE”, “tHE”, and “THE”.
If the file name that the user entered does not exist, (i.e., cannot open the file in the reading mode)
print “Cannot open file.” and terminate the program.
If you are using macOS, make sure to turn off SandBox, or your program won’t be able to read a file.
Sample console output:
Enter File Name>C:/Users/soji/text1.txt
Enter Keyword>small
14: practically usable solution has been found. The smallest known
19: is unknown whether 88-element solution is the smallest possible
Appeared 2 times.
PS6-2 Wall Clock Animation (ps6-2.cpp) [50 points]
The following sample program prints current time on the console window.
#include <stdio.h>
#include <time.h>
void GetLocalTimeHourMinSec(int &hour,int &min,int &sec)
{
struct tm *localTime;
time_t t=time(NULL);
localTime=localtime(&t);
hour=localTime->tm_hour;
min=localTime->tm_min;
sec=localTime->tm_sec;
}
int main(void)
{
int hour,min,sec;
GetLocalTimeHourMinSec(hour,min,sec);
printf(“%d %d %d\n”,hour,min,sec);
return 0;
}
In PS6-2, you write a program that draws a clock that shows the current time on the graphics window.
The specification is same as Problem Set 3, except that your Second arm needs to be red.
Your program needs to update the clock until the user presses the ESC key.
You can cut & paste from the sample solution to Problem Set 3, or what you submitted for PS3.
Save your program as ps6-2.cpp and include in the zip file you submit to the Canvas.
Second arm


