C/C++ 编程辅导

C/C++程序辅导 辅导C/C++编程作业

C++ Program Design

Raven Elevators Inc. (REI), a manufacturer of elevators, has hired you to build them a simulator for their line of elevator control systems. You happily accept the task, eager to impress your new employer with your development skills. REI asked you to implement it in Qt C++, but before doing the implementation REI requested that you first deliver use cases, design documentation, traceability matrix, and C++ class interfaces.
Learning objectives:
 Designing and expressing your design in UML
 Verifying consistency between use cases and design
 Building a requirements traceability matrix
 Designing for variability in elevator allocation strategy
 Use cases (can borrow from A1 & grading feedback)
 Design documentation – structure and behavior:
o UML Class diagram
o Sequence diagrams for these scenarios: 1 Basic use cases and 5 safety features
o Activity or state diagram (where relevant)
o Textual explanation of your design decisions including use of design patterns, if any.  C++ header files (interfaces and significant variables)  Traceability matrix
Your design should include passenger and sensor actors driving the elevator controller responses that are displayed through a simple GUI.
Your design should accommodate for variability in elevator allocation strategy (handle 2 or more allocation strategies).

Elevator system specification (same as Assignment 1)
<Paragraph 1> A building is serviced by M elevators (also called cars). On each of the N floors is a pair of buttons marked “up” and “down. When a button is pressed it illuminates, and remains illuminated, until an elevator arrives to transport the customers who, at this floor, have requested an elevator going in a certain direction. When the elevator arrives, it rings a bell, opens its doors (the elevator and floor doors) for a fixed time (10 seconds) allowing people to exit or board, rings the bell again, closes its doors and proceeds to another floor. Once on-board passengers select one or more destination floors using a panel of buttons; there is one button for every floor. The elevator has a display which shows passengers the current floor of the elevator. There is also a pair of buttons on the elevator control panel marked “open door” and “close door”. These buttons can be used by a passenger to override the default timing of the doors. The door will remain open beyond its default period if the “open door” button is held depressed; the doors can be closed prematurely by pressing the “door close” button. Inside the elevator there is also a help button linked to building safety service.
<Paragraph 2> Each elevator has a sensor that notifies it when it arrives at a floor. The elevator control system should ensure that the group of elevators services all (floor and on-board) requests expeditiously.
<Paragraph 3> Each elevator has a display and an audio system. The display shows the current floor number and warning messages that are synced with audio warnings.
Safety features:
<Paragraph 4> Help: The control system receives a “Help” alarm signal from an elevator indicating that the “Help” button has been pressed. In that case, the passenger is connected to building safety service through a voice connection. If there is no response from building safety within 5 seconds or if there is no response from a passenger a 911 emergency call is placed.
<Paragraph 5> Door obstacles: If the light sensor is interrupted when the door is closing, the control system stops the door from closing and opens it. If this occurs repeatedly over a short period of time, a warning is sounded over the audio system and a text message is displayed.
<Paragraph 6> Fire: The control system receives a “Fire” alarm signal from the building and commands all elevators to move to a safe floor. Similarly, a “Fire” alarm signal from the elevator itself will cause that elevator to go to a safe floor. In both cases an audio and text message are presented to passengers informing them of an emergency and asking them to disembark once the safe floor is reached.
<Paragraph 7> Overload: The control system receives an “Overload” alarm signal from an elevator if the sensors indicate that the passenger or cargo load exceeds the carrying capacity. In that case, the elevator does not move and an audio and a text messages are presented to passengers asking for the load to be reduced before attempting to move again.
<Paragraph 8 > Power out: The control system receives a “Power Out” alarm signal. In that case, an audio and a text messages are presented to passengers informing them of the power outage. Each elevator is then moved to a safe floor and passengers are asked to disembark via audio and text messages. The battery backup power is sufficient to do all of this.

Core Scanner

The goal of this project is to build a scanner for a version of the Core language, a pretend
language we will be discussing in class.
For this project you are given the following:
ˆ \3341 Project 1.pdf” – This handout. Make sure you read it completely and handle all
requirements in your implementation. You are encouraged to post any questions on
ˆ \main.c”, \core.h”, \scanner.h”, \scanner.c” – I have outlines the project in this les,
and give you some of the code you will need. Make no changes to to \core.h” le.
You can make changes to \main.c” as long as those changes do not change break my
tester.sh script.
ˆ You may create additional les to contain any additional classes or methods you want
to create.
ˆ \tester.sh” – This is a script I wrote to help you test your project. It is very similar
to the script that will be used to grade your project, so if your project works correctly
with this script you are probably doing well. The only guarantee I give is that this
script will work on stdlinux.
ˆ Folder \Correct” – This contains some correct inputs and their expected outputs. The
\tester.sh” script will test your code against these examples.
ˆ Folder \Error” – This contains some inputs that should generate error messages. The
\tester.sh” script will test your code against these examples.
The following are some constraints on your implementation:
ˆ Do not use scanner generators (e.g. lex, ex, jlex, j ex, ect) or parser generators
(e.g. yacc, CUP, ect)
ˆ Use only the standard libraries of C. This is the reference I like to use:
Your submission should compile and run in the standard linux environment the CSE
department provides (stdlinux). I will leave it up to you to decide what IDE you will use or
if you will develope your code locally or remotely, but as a nal step before submitting your
code please make sure it works on stdlinux. Use the subscribe command – make sure
you are subscribed to GCC-10.1.0. The graders will not spend any time xing your
code – if it does not compile on stdlinux, your project will not be graded and you
will get a 0.

Your Scanner
You are responsible for writing a scanner, which will take as input a text le and output a
stream of \tokens” from the core.h enumeration. You scanner must implement the following
ˆ scanner open and scanner close: These functions open the le, nd the rst token, and
release memory when we are done scanning.
ˆ currentToken: This function should return the token the scanner is currently on, with-
out consuming that token.
ˆ nextToken: This function should advance the scanner to the next token in the stream
(the next token becomes the current token).
ˆ getId: If the current token is ID, then this function should return the string value of
the identi er. If the current token is not ID, behavior is unde ned.
ˆ getConst: If the current token is CONST, then this function should return the value
of the constant. If the current token is not CONST, behavior is unde ned.
All of these functions will be necessary for the parser you will write in the second project.
You are free to create additional functions.
To make things easier for you, you may assume no token is made of more than 20
characters. Also, I suggest using calloc to allocate memory, instead of malloc.
The input to the scanner will come from a single ASCII text le. The name of this le will
be given as a command line argument to the main function.
The scanner should process the sequence of ASCII characters in this le and should
produce the appropriate sequence of tokens. There are two options for how your scanner can
(1) the scanner can read the entire character stream from the le, tokenize it, stores all the
tokens in some list or array and calls to currentToken and nextToken simply walk through
the list
(2) the scanner reads from the le only enough characters to construct the rst token, and
then later reads from the le on demand as the currentToken or nextToken functions are
Real world scanners typically work as described in (2). In your implementation, you can
implement (1) or (2), whichever you prefer.
Once your scanner has scanned the entire le, it should return the EOS token (End Of

Invalid Input
Your scanner should recognize and reject invalid input with a meaningful error message. The
scanner should make sure that the input stream of characters represents a valid sequence of
tokens. For example, characters such as ` ‘ and ‘%’ are not allowed in the input stream. If
your scanner encounters a problem, it should print a meaningful error message to standard
out (please use the format “ERROR: Something meaningful here”) and return the ERROR
token so the main program halts.
The Language
The Core language consists of 4 kinds of strings, which you will need to tokenize:
ˆ Keywords:
and begin do else end if in integer
is new not or out procedure record then while
ˆ Identi ers:
Begins with a letter (uppercase or lowercase) followed by zero or more letters/digits.
Refer to this regular expression once we cover regular expressions:
(aj : : : jzjAj : : : jZ)(aj : : : jzjAj : : : jZj0j1j : : : j9)*
ˆ Constants:
Integers from 0 to 1009 (inclusive)
ˆ Symbols:
+ – * / := = < : ; . , ( ) [ ]
Your scanner walk through the input character stream, recognize strings from the lan-
guage, and return the appropriate token from the enumeration in \Core.java” or \Core.py”.
If there is any situation in which it is unclear to you which token should be returned, please
ask for clari cation on Piazza.
Write your scanner with these rules in mind:
1. The language is case sensitive, and the keywords take precedence over the identi ers.
For example, \begin” should produce the token BEGIN (not ID), but \bEgIn” should
produce the token ID.
2. Strings in the language may or may not be separated by whitespaces. For example the
character stream may contain the string \x=10″ or the string \x = 10″, and both of
these should generate the token sequence ID EQUAL CONST.
3. Always take the greedy approach. For example, the string \whilewhile” should produce
an ID token instead of two WHILE tokens, string “123” should produce a single CONST
token, and string \:=” should produce ASSIGN.

4. Keyword/identi er strings end with either whitespace or a non-digit/letter character.
For example:
(a) the string \while (” and the string \while(” should both result in the WHILE and
LPAREN tokens.
(b) the string \while 12″ should result in the WHILE and CONST tokens, but the
string \while12″ should result in the ID token.
5. Constant strings end with any non-digit character. For example:
(a) the string \120while” or \120 while” should result in the CONST and WHILE
6. Symbols may or may not be separated from other strings by whitespace. For example:
(a) String \++while<= =12=” should result in the token sequence ADD ADD
Let me know if you think of any situations not covered here.
Testing Your Project
I have provided some test cases. For each correct test case there are two les (for example
4.code and 4.expected). On stdlinux you can redirect the output of the main program to a
le, then use the di command to see is there is any di erence between your output and the
expected output. For an example of how to do this you can take a look at the script le
The test cases are weak. You should do additional testing with your own test cases. Feel
free to create and post additional test cases on piazza.
Project Submission
On or before 11:59 pm January 27th, you should submit to the Carmen dropbox for Project
1 a single zip le containing the following:
ˆ All your .java or .py les.
ˆ An ASCII text le named README.txt that contains:
{ Your name on top
{ The names of all les you are submitting and a brief description stating what each
le contains
{ Any special features or comments on your project
{ Any known bugs in your scanner  If the time stamp on your submission is 12:00 am on January 28th or later, you will
receive a 10% reduction per day, for up to three days. If your submission is more than 3
days late, it will not be accepted and you will receive zero points for this project. If you
resubmit your project, only the latest submission will be considered.
The project is worth 100 points. Correct functioning of the scanner is worth 65 points. The
handling of errors is worth 20 points. The implementation style and documentation are
worth 15 points.

C++ Assignemnt


C++ Assignemnt


Use a Linked List and a set of Derived Classes from a Base Class to demonstrate polymorphism in C++. To do so, alter linked-list source code to run a family of mobile phone derived classes, and create a menu to demonstrate the functionality.  Students are allowed  to work in groups or cohorts. For ease of submission, please e-mail the instructor the members of your cohort before the due date.


The Linked List


Sample code is available to create a linked list on Blackboard.  Alter this code to create a linked list capable of handling the derivation tree of a series of mobile phones. The base class is mobile phone.


The linked list must be an independent class, and must have the following data and functions:

  • MobilePhone * head – a pointer to the first location in the linked list.
  • MobilePhone * tail – a pointer to the last location in the linked l

Loops, Arrays, Constructors, Methods

Loops, Arrays, Constructors, Methods

In languages that use the same or similar alphabets, some characters will occur with greater frequency that others. Consider the Latin alphabet, for example, used by most of Western and Central Europe and other parts of the world. Some languages, for example, may not use all of the 26 characters that we are used to. You can learn a lot about languages by comparing the relative frequencies of character use.

A table of frequencies might look something like this:

          *     *               
          *     *               
          *   * * *             
          *   * * *             
          *   * * *             
        * *   * * *             
      * * *   * * *             
      * * * * * * * *           
      * * * * * * * *           
      * * * * * * * * *         
      * * * * * * * * *         
      c d e l m n o p v 

In this project, we will write a program that takes

C++ Basic

#1. Timetest (30 points with 25 points for write-up and 5 points for timetest.cpp) The purpose of this question is to explore how different ADTs affect the runtime of a program.  The program simply inserts and/or deletes data items from an ADT.  The sequence of insert and delete operations is specified in a data file.  You will find four data files (File1.dat, File2.dat, File3.dat, and File4.dat) in ~neff/60/p1 that model different types of behavior and you should use these to analyze the performance of different ADTs.  The first line of each data file summarizes the operations in the file.    You will submit a typed, double-spaced, 2-4 page report (writeup.pdf) that summarizes your findings on the performance of each ADT for these different sets of operations.  Also submit the driver program described below.


Start by writing a driver program, timetest.cpp, that will ask for the name of an input file that contains a list of commands and then repeatedly ask the user for the ADT t

Parallel Computing and Dijkstra's Algorithm

Department of Computer Science Intro to Parallel Computing
Programming Assignment 3
Due Wednesday, October 28 at 6 pm
Dijkstra’s Algorithm
Edsger Dijkstra was a Dutch computer scientist. He is unquestionably one of the found-
ing fathers of computer science. In addition to devising Dijkstra’s algorithm, he was one
of the originators of structured programming | a precursor to modern object-oriented pro-
gramming. C, for example, is a structured programming language. He also made many
contributions to the solution of process-coordination problems in parallel computing: we’ll
learn about several later on in the course. His Wikipedia page lists more than fty funda-
mental contributions to computer science.
Dijkstra’s algorithm solves the single-source shortest path problem” in a weighted, di-
rected graph. The input consists of a weighted, directed graph and a speci ed vertex in the
graph. A directed graph or digraph is a collection of vertices and directed edges, which join
one vertex to another. A weighted dig

Battleship Recursion

CSCI-1200 Data Structures | Fall 2015
Homework 6 | Battleship Recursion
In this homework we will solve ship placement puzzles inspired by the pencil & paper Battleship” game that
was later made into a board game by Milton Bradley and then a puzzle that is a regular feature in Games
magazine. You can read more about the history of the game and see examples here:
This is a popular game with lots of material available online. You may not search for, study, or use any code
related to the Battleship game or puzzle. Please carefully read the entire assignment and study the examples
before beginning your implementation.

Linked lists #2


This assignment extends your work on hw06 with linked lists, but also includes an extra focus on algorithmic complexity. The goals are as follows:

  1. Learn how to keep data separate from containers
  2. Practice designing algorithms and data structures
  3. Practice using code that uses the following:
    1. linked lists
    2. structures for data encapsulation
    3. dynamic memory (i.e., malloc)
    4. struct initializer syntax (C99)
  4. Learn how analyze the complexity of algorithms

C++ basic

For this problem, you will use the rand function (srand, time) to generate a sequence S of k random integers in the range [m, m+1, …, n].

You will need to prompt the user to enter values for k, m, and n in your main function. Implement the MergeSort sorting technique as follows:

– Make a function called get_random that returns a random integer in the range [m, m+1, …, n]

int get_random(int m, int n)

c++ programm assignments

This project is the main assessment of this subject. It is worth 40% of your total

assessment. You are required to write a C++ program to solve all problems. All work is

to be completed individually. If parts or all of the source code you submit is not your own

work, you will receive ZERO.

Part 1. Design

This first part is worth 20% of you total assessment. It is consist of 5 tasks. You need to


• Programming object list

• Algorithm

• C++ Coding

Task1: Miles per Gallon.

A liter is 0.264179 gallons. Write a program that will read in the number of liters of

gasoline consumed by the user’s car and the number of miles traveled by the car, and

will then output the number of miles per gallon the car delivered. You must show the

outputs as given in the example. You must show the numbers in fixed point left justified

and in three decimal places as in the example.


This program read the number of liters of gasoline consumed (gasoline In

Liters) and the number of miles traveled by the ca