C++代写:CS362 CGI Program

代写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.

  1. The Movie.h and Movie.cpp modified as part of this homework
  2. 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:

  1. 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.
  2. 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.
  3. 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.
  4. 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

  1. First play with the demo website using sample inputs and outputs to ensure you form a good mental model of the operation.
  2. Use the solutions for lab exercises as reference to implement the necessary functionality.
  3. Needless to add you should URL-decode all values input via CGI.
  4. Remove any trailing newline (‘\n’) characters in numerical inputs. Otherwise you may get errors when calling std::stoi.
  5. Use SQL LIKE clause to search for substrings.
  6. Think about using if-statements to add additional conditions to your SQL query
  7. 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.
  8. 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.
  9. The above feature enables you have just 1 SQL statement to develop this program, thereby making this assignment an cinch.
  10. You will need to add a constructor or setter methods to the supplied Movie class to set values in instance variables.
  11. 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:

  1. The Movie.h and Movie.cpp modified as part of this homework
  2. 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.