EE11032 C++ Programming and software Engineering II

qq1703105484

Problem 1

Write a function

Int[] union_Array (int a[], int lenA, int b[], int lenB)

that constructs the union of two integer arrays and removes any element that occurs more than once. For example, if two arrays of the union_Array are {1, 8, 16 } and {11, 8, 7, 1}, it will return an array

of {1, 8, 16, 11, 7}.

Tasks:

  1. The length of two arrays should be different and defined by constants using “#define”.

  1. Arrays are inputted from the keyboard.
  2. Call the function union_Array in your main function. Initialize two arrays. Print out the new array (there is no requirement for the order of the output elements).
  3. Compile and run correctly

Problem 2

 

Given a student class to represent student information as follows: class Student{

string stuId; string name;

double mathScore; double chineseScore; double englishScore;

};

Write a program to achieve the following tasks:

  1. Use an array to save student information. The length of the array should be defined by a constant using “const”.
  2. Student information is inputted from the keyboard.
  3. Print out the student ID and average mark of three courses for each student in a descending sequence.
  4. Print out student ID whose average mark is smaller than the average mark of all students.

  1. Compile and run correctly.

Problem 3

 

Given a student structure to represent student information as follows: structure student{

string stuId; string name;

double mathScore; double chineseScore; double englishScore;

};

Write a program to achieve the following tasks:

  1. Use a pointer and linked list to save student information. The length of the linked list (number of student objects) should be inputted from the keyboard.
  2. Student information is inputted from the keyboard.
  3. Print out the student ID and average mark of three courses for each student in a descending sequence.
  4. Print out student ID whose average mark is smaller than the average mark of all students.
  5. Compile and run correctly.

Problem 4

 

Given a function header as char *findC (char const *source, char const *obj): Write a program to achieve the following tasks:

  1. Write a function to search a character sequence pointed to by a pointer (called “obj”), in another character sequence (called “source”). Return the pointer pointing to the found character. If there is more than one target found in the source, return the pointer pointing to the first one. (2 marks)

Eg1: search for “C” in “ABCDEF”, return the pointer point to ‘C’. Eg2: search for “Z” in “ABCDEF”, return a NULL pointer.

Eg3: search for “CD” in “ABCDEF”, return the pointer point to ‘C’. Eg4: search for “CF” in “ABCDEF”, return a NULL pointer.

Eg5: search for “A” in “ABCAFC”, return the pointer point to the first ‘A’.

  1. Write a main function to input two strings by the keyboard and print the position of the pointer in the source string(print -1 if the function returns a NULL pointer).
  2. Compile and run correctly.

Problem 5

 

Given a circle class to represent circle information as follows: class Circle{

int x; int y;

double radius;

};

Write a program to achieve the following tasks:

  1. The centre point of (x,y) and radius should be inputted from the keyboard.
  2. Define a method that can calculate and return the circle’s area.
  3. Define an overloading operator + to add two circle objects and get a new circle object. The centre point of the new circle object is the same as the centre point of the first circle object. The area of the new circle object should be the sum of the areas of two circle objects (You can calculate the radius of the new circle based on the sum of the area of two circles).

  1. Define a function to print relations of two circles(interaction, tangency, separation and inside)
  2. Define a main function to input two circle objects, get a new circle object based on these two circle objects and print the relations of these two circle objects.
  3. Compile and run correctly.

Problem 6

 

Given a set of x,y data points, it is often necessary to automatically calculate an equation which gives the best fit line through the data. This type of analysis is known as line fitting or regression analysis.

The mathematical basis behind line fitting is shown below. You have a set of data points represented by (x1,y1), (x2,y2)..................... (xn, yn). You want an equation which represents this data, the exact type of

equation will depend on the way in which the data varies. Given any mathematical relationship between x and y it should be possible to generate a line fitting algorithm. The line fitting algorithm is described below.

Straight line

The equation for a straight line is: y = ax + b. Suppose that we have n points of (x,y) values from the text file, the values of a and b for the best fit line that is the best approximation of the given set of data points can be obtained from the following equation:

b1                  d1

b2        d2

a1        b1

a2         b2

a1        d1

a2        d2

a1        b1

a2        b2

a =                   , b = -

where

n                                                                      n

a1 = å( xi *xi ) ,

i=1

n

b1 = å xi ,

i=1

 

a2 = å xi ,

i=1

b2  = n ,

n

d1 = -å( xi *yi ) ,

i=1

 

n

d2 = -å yi

i=1

The value of a second order determinant  a1

a2

 

b1

is the difference between the two dot products

b2

(a1b2 - a2b1). Create a C++ program to calculate its value.

Distance

The distance from a point P(x,y) to the line ax+by+c=0 is the length of the perpendicular line from the point P to the line:

Distance =

 

|ax+by+c|

√𝑎2+𝑏2

where (x,y) is the coordinate value for point P.

Standard error of distance for all the points: SE=√

 

𝑛

𝑖=1

(𝑥𝑖−𝑥̅)2

𝑛−1

Where 𝑥̅ is the mean distance of all points, 𝑥𝑖 is the distance of Point Pi , n is the number of all points.

Please complete the assessment according to the following steps:

  1. Create a file operation class “FileOp” with functions as follows:
    1. It can allow users to input points from the keyboard and save these points into a text file.
    2. It can read points from the text file.
    3. It can delete a point from the text file.
    4. It can check if a point is in the text file.
  2. Create a class “LineFitting” with functions as follows:
    1. It can calculate the parameters of a, b and c for the best fit line ax+by+c=0.
    2. It can calculate the distance between each point in your file and the best fit line.
    3. It can find the best point from the file, which is not in the best fit line but has a minimal distance compared to other points.
    4. It can find the worst point from the file, which has the maximal distance compared to other points.
    5. It can calculate the standard error of distance for all the points.
  3. Create a main method in your program to achieve the following functions:
    1. Create a main method.
    2. Create a text file using the “FileOp” class with some points.
    3. Print out the equation of the best fit line (e.g. 3x+2y+3=0).
    4. Ask the user to input a point and print out whether the point is in the text file or not. If it is in the file, then print out its position.
    5. Print out the worst point that has a maximal distance to the best fit line in all the points. Print out the standard error for all the points.

f)

g)    Ask the user to input a point and delete it from the file if the point exists in the text file.

Problem 7

 

Online trading systems can help customers buy goods from the internet. In this question, you are required to write a program to simulate the trading procedure and allow customers to query and buy some goods.

Tasks:

  1. Create a Product class with several private member variables, such as product id, product name, product amount and price.
  2. Create a base class Person with several private member variables, such as person name, gender, mobile number and address. The gender should be an enum.
  3. Create a subclass Customer based on the Person class. It has extra private member variables, such as customer id, capital and a vector of products the customer is purchasing. Each customer has 10,000 RMB initial capital.
  4. Create a subclass Manager based on Person class. The manager has extra private member variables, such as age and title.
  5. Create a MainProcess class. It has private member variables, such as a vector of products to save all product information, a vector of customers to save all customers, a manager who can manage customers and products, a customer who is purchasing products. In addition, it also has some functions to output operation menus both for managers and customers to choose from.


  1. When the program runs, it shows a menu as follows:

Fig.1. Main operation menu

There are two roles in this online trading system (manager and customer). Different roles have different functions.


  1. If the input is 1, then move to manager’s menu as follows:

Fig.2. Manager’s operation menu

The manager can add new products, query products, add new customers and query customers. If the user inputs 5, then the program will move to the parent menu shown in Figure 1 (main operation menu).


    1. Add products: manager can add new products into a product vector so that customers can buy these products.

Fig.3. Operation of adding products

The manager can continue to input product id, name, amount and price to create and add  new products into the product vector. Duplicated product id cannot be added to the product vector. When the manager input 0 to stop adding, the manager operation menu will output on the window, and the manager can input another number to do other operations.


    1. Query products: manager can input a product id to query a particular product or input “*” to list all products in the product vector. Output “No product found!” if there is no particular product.

Fig.4. Operation of querying products


    1. Add customers: manager can add new customers to the customer vector.

Fig.5. Operation of adding customers

The manager can input customer id, name, gender, mobile number and address to create and add new customers into the customer vector. Duplicated customer id cannot be added to the customer vector. When the manager inputs 0 to stop adding, the manager operation menu will be outputted on the window, and the manager can input another number to do other operations.


    1. Query customers: manager can input a customer id to query a particular customer or input “*” to output all customers in the customer vector. “No customer found!” will be outputted if there is no particular customer.

Fig.6. Operation of querying customers

    1. Move to parent menu: if the manager inputs 5, then the program moves to the main operation menu shown in Figure 1.
  1. On the main operation menu, if the user inputs 2, then the system will ask the user to input a customer id to confirm which customer will purchase products. If the customer id exists in the customer vector, then the operation menu for customers will be outputted as Figure 7 shows.

Fig.7. Customer’s operation menu


otherwise, ask users to input a new customer id or a special string “quit” to move to the parent operation menu shown in Figure 8 (it means that you should create at least one customer before you can enter into the customer operation menu and start to purchase products).

Fig.8. Failed to find the customer Id


    1. Add products into cart: a customer can add products into the cart so that the customer can buy these products. Customer can input product id and the amount he/she wants to buy. The program will show a reminder if the customer does not have enough capital or the amount the customer wants is larger than the available amount of the product. The program should output successful information if the adding operation runs successfully. In addition, the amount of product in the product vector should be deducted accordingly.

Fig.8. Operation of adding products into cart

    1. Query products in cart: customers can query all products added in the cart. The customer can input a specific product id to query one product or input “*” to list all products in the cart.

Fig.9. Operation of querying products in cart


    1. Check up: customer can check up the bill for all products in the cart. It will list customer’s id, name, gender and capital, all products in the cart and the total price.

Fig.10. checking up operation

If the cart is checked up successfully, the capital of the customer should be deducted based on the total price of products the customer has bought.

  1. Make sure your source code has some comments to help us understand and can be compiled successfully
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值