代写CGI应用程序,支持数据库访问。
Submission Instructions
This homework assignment must be turned-in electronically via Canvas. Ensure
your program compiles (without any warnings or style errors) successfully.
Ensure you have tested operations of your program as indicated. Once you have
tested your implementation, upload just the 1 source file onto Canvas via the
CODE plug-in.
- The Movie.h and Movie.cpp modified as part of this homework
- The homework6.cpp C++ source file modified for this homework.
General Note
Upload each file associated with homework (or lab exercises) individually to
Canvas. Do not upload archive file formats such as zip/tar/gz/7zip/rar etc.
Objective
The objective of this homework is to:
- Develop a Common Gateway Interface (CGI) program
- Process inputs with URL-encoding
- Run SQL queries on a database and process results
- Work with a simple C++ class to manage results from a database.
Grading Rubric
The program submitted for this homework must pass necessary base case test(s)
in order to qualify for earning any score at all. Programs that do not meet
base case requirements or just skeleton code will be assigned zero score!
Program that do not compile, have even 1 method longer than 25 lines, or just
some skeleton code will be assigned zero score.
- -1 Points: for each warning generated by the compiler.
- NOTE: Violating CSE programming style guidelines is a compiler error! Your program should not have any style violations reported in NetBeans when you compile it.
Starter Code
- Movie.h, Movie.cpp: For this homework you are supplied with a Movie class. You may modify these 2 files as needed. Review the Movie::printAsHtml method. You must use this printAsHtml method to print Movie information (if you don’t use this method to print Movie information you automatically get zero for this homework)
- homework6.cpp: For convenience you are supplied with a starter code with some of the HTML formatting information to streamline printing results in HTML.
- hw6.html and movies.css: Do not modify or submit these 2 files. Optionally, you can use these 2 files to setup your own website (to showcase your work for jobs/internships) in your public_html using the procedure from prior labs.
Background
A Movies table has been created and populated with information about movies.
The structure of the table is shown below:
mysql> desc Movies;
+———+————–+——+—–+———+——-+
|Field |Type |Null |Key |Default |Extra |
+———+————–+——+—–+———+——-+
| id | int(8) | NO | PRI | NULL | |
| title | varchar(256) | NO | MUL | NULL | |
| year | int(4) | NO | MUL | NULL | |
| genres | varchar(128) | NO | | NULL | |
| imdb_id | int(9) | NO | | NULL | |
| rating | float(7,5) | NO | | NULL | |
| raters | int(6) | NO | | NULL | |
+———+————–+——+—–+———+——-+
In this homework you will be developing a custom C++ program that can find
movies matching one-or-more of the following conditions specified by the user:
- title: If this input is specified (i.e., not an empty string) then this specifies the partial (i.e., substring) title for the movie the user is interested in.
- genre: If this input is specified (i.e., not an empty string) then this specifies a partial (i.e., substring) for the genre for the movie the user is interested in.
- startYear: If this input is specified (i.e., not an empty string) then this specifies the earliest year to search for movies. For example, if startYear=2000, then return only movies with year ]= 2000.
- edYear: If this input is specified (i.e., not an empty string) then this specifies the latest year to search for movies. For example, if endYear=2016, then return only movies with year [= 2016.
Note: You may assume at least one of the above inputs will be specified. Each
of the above inputs restricts the scope of the search. For example, if
title=atri, genre=”Anim”, startYear=1990, and endYear=2016, then the search is
for a movie whose title contains the substring “atri” and genre contains the
substring “anim”. If any of the inputs are not specified, then the
corresponding restriction is not applicable
Demonstration site
An example website is available. You can use the above website to form a
stronger mental model on the expected user-experience for his assignment.
Homework Assignment
Develop a CGI-bin compatible C++ program that can process 1-line of input in
the following manner:
Base case
The program should extract the title value and print movies whose title
contains the specified substring.
Extra functionality #1
If genre is specified, the program should print movies whose genre contains
the specified substring. The program should handle cases where the title or
genre may or may not be specified.
Extra functionality #2
If startYear or endYear inputs are specified then the program should restrict
movies to those years appropriately.
Tips
- First play with the demo website using sample inputs and outputs to ensure you form a good mental model of the operation.
- Use the solutions for lab exercises as reference to implement the necessary functionality.
- Needless to add you should URL-decode all values input via CGI.
- Remove any trailing newline (‘\n’) characters in numerical inputs. Otherwise you may get errors when calling std::stoi.
- Use SQL LIKE clause to search for substrings.
- Think about using if-statements to add additional conditions to your SQL query
- Use bind variables to streamline your query. Keep in mind you can specify more bind variables in the store() statement than used. For example, even though your query may only have %1 as the only bind variable, you can still call query.store(year, genre, startYear, endYear); with 4 variables.
- Using the lab exercises as reference, develop a program with hardcoded values to test the operations of the above store method. Developing test program is the best way to improve your understanding. This type of learning (i.e., building small test programs) is a key expectation in jobs and internships.
- The above feature enables you have just 1 SQL statement to develop this program, thereby making this assignment an cinch.
- You will need to add a constructor or setter methods to the supplied Movie class to set values in instance variables.
- This would be a good project to showcase for jobs after you add more features of your own.
Sample inputs and outputs
Note: Some of the output appear wrapped in the sample output below. User
inputs are shown in bold.
Turn-in
This homework assignment must be turned-in electronically via Canvas CODE
plug-in. Ensure you have tested operations of your program by setting up your
website. Once you have tested your implementation, upload the following 3
source files onto Canvas:
- The Movie.h and Movie.cpp modified as part of this homework
- The homework6.cpp C++ source file modified for this homework.
Upload all the necessary C++ source files to onto Canvas via the CODE plug-in.
Do not submit zip/7zip/tar/gzip files. Upload each file independently.