Assignment 1 Front Sheet: Date Received 1st Submission

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 1: Programming

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Nguyen Thanh Loc Student ID GBH18350

Class GCH0716 Assessor name Truong Cong Doan

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.

Student’s signature Loc

Grading grid

P1 M1 D1
❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
Contents
1. Introduction: ........................................................................................................................................................................................................ 5
1.1 Introduction to general content: ..................................................................................................................................................................... 5
1.2 Summary of content of assignment:............................................................................................................................................................... 5
2. Algorithm .............................................................................................................................................................................................................. 5
2.1 What is algorithm? ......................................................................................................................................................................................... 5
2.2 Characteristics of algorithms ............................................................................................................................................................................... 6
2.3 Example ............................................................................................................................................................................................................... 6
3. Problem ................................................................................................................................................................................................................. 7
3.1 Business problem ........................................................................................................................................................................................... 7
3.2 Example ......................................................................................................................................................................................................... 7
4. Design and develop program .............................................................................................................................................................................. 7
4.1 Input/output .................................................................................................................................................................................................... 7
4.2 Identify algorithm .......................................................................................................................................................................................... 7
4.3 Flowchart: ...................................................................................................................................................................................................... 7
5. Design functions of program ................................................................................................................................................................................ 10
6. Implementation and introduction to code ........................................................................................................................................................... 12
6.1 Demo and test .................................................................................................................................................................................................... 12
6.2 The idea, the algorithm needs to use, usability when put into practice: ............................................................................................................ 15
6.3 Introduction to code ........................................................................................................................................................................................... 15
7.Test plan................................................................................................................................................................................................................... 23
8. Comments and repairs in the future. ................................................................................................................................................................... 24
9. References ............................................................................................................................................................................................................... 25
1. Introduction:
1.1 Introduction to general content:
To demonstrate basic problem solving and programming skills. You must prepare a report on the use of algorithms to solve
the problem. You need to explain, use examples, how to use algorithms to solve simple business problems and the steps
needed to implement a work program solution. You should clarify your assumptions about your program. Problems to be
addressed will involve basic procedural programming instructions - sequence instructions (inputs, outputs and assignment
statements), loops, conditional statements. Issues need to be analyzed and designed using diagrams and representations
using modules (processes) using menu-based programs.
1.2 Summary of content of assignment:
Create a small company management software.

2. Algorithm
2.1 What is algorithm?
-An algorithm is a step-by-step description of the solution to a problem
An algorithm must be:
Definite
Finite
Precise and Effective
Implementation independent.
-Algorithm is used a lot in life such as to compare, cash, or simply in mathematics, …
2.2 Characteristics of algorithms
-Input: An algorithm that has input values from a specified set.

- Output (Output): From each set of input values, the algorithm will generate output values. The output values are the solutions
of the problem.

- Stop calculation: After a finite number of steps the algorithm must stop.

- Determination: At each step, the operation steps must be very clear, not causing ambiguity. To be more specific, in the same
condition the two processors that perform the same step of the algorithm must give the same results.

- Correctness (efficiency): First of all, the algorithm needs to be correct, that is, after putting the data into operation algorithm
and giving the desired result.

- Popularity: The algorithm can solve any problem in the class of problems. Specifically, the algorithm may have different data
sets within a specific domain.
2.3 Example
Given two real numbers a and b. Please indicate the results comparing the two of them as "a greater than b", "a is less than b"
or "a equals b"

Identify the problem:

Input: two real numbers a and b


Output: results compare
description algorithm:

Step 1. If a> b, the result is "a greater than b" and go to Step 3
Step 2. If a <b, the result is "a less than b"; vice versa, the result is "a equals b"
Step 3. Finish algorithm
3. Problem
3.1 Business problem
As the management accountant salaries of everyone in the company. You need to accurately calculate wages that people
get every month.
 Recipe:
Salary = salary 1 day * number of days + allowances
 Find information with name or department.
 Sort by salary.
3.2 Example
If Long is the manager in the company. He has 30 days took attendance with 1.200.000 vnd 1 day and 2.000.000 Money
allowance. He will have:
Long’s salary = 1.200.000 x 30 + 2.000.000= 38.000.000 vnd

4. Design and develop program

4.1 Input/output
In put: Full name; department: use for find information
number day attendance; 1 day's salary: use for Payroll
Output: salary and Position.

4.2 Identify algorithm


4.3 Flowchart:
Designed flowchart of case 3: Sort by salary
h1: flowchart for sort
Designed flowchart of case 2: find information with name
h2 find with name

explain:
-In h1, First, the data entered (a, b) will be taken to calculate the salary. Next, create i with j, assign the data entered in i
and j. then compare i; j. If i> = j, print the data assigned to i first then j. it will assign and compare to the end.
-In h2, First enter the name to search, then perform a scan of the data entered from the beginning to the end, if the same
name, data will exported to the screen. Perform a scan until there are no duplicate names. if not, it will print the "Name
does not exist."

5. Design functions of program


First use “delegate” to call and represent the declared data:
do while, for, switch case: make menu

bool check: use for find information in case 2;

if else: make menu too;


6. Implementation and introduction to code

6.1 Demo and test


* menu table:
Table 1:

That is enter number of member that you want for add data.

When you input data


Table 2:

Find information with name


Table 3:

Display all and short by salary

6.2 The idea, the algorithm needs to use, usability when put into practice:
The program helps payroll and find information faster. It helps save time for accountants. Methods of presentation and implementation
of algorithms is my experience has been accumulated during the study, however, the program still has many shortcomings, needs to be
developed in the future.

6.3 Introduction to code


*. My code:

using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace asm

class Program// input data


{
delegate member CreatMember();
delegate void display(ArrayList arrlist);
static member Member()
{
int temp;
member member = new member();
Console.WriteLine("Full name : ");
member.name = Console.ReadLine();
Console.WriteLine("Department : ");
member.department = Console.ReadLine();
Console.WriteLine("Number day attendance : "); // a in flowchart
member.a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("1 day's salary : "); // b in fowchart
member.b = int.Parse(Console.ReadLine());
Console.WriteLine("Position :");
Console.WriteLine("1.Manager 2.Deputy 3.Employees");
temp = Convert.ToInt32(Console.ReadLine());
switch (temp)
{
case 1:
member.Position = "Manager";
member.Updatec();
break;
case 2:
member.Position = "Deputy";
member.Updatec();
break;
case 3:
member.Position = "Employees";
member.Updatec();
break;
}
return member;
}
static void Display(ArrayList arrlist)// display and sort the list
{
Member[] cb = new Member[arrlist.Count];
Member temp;
int k = 0;
foreach (Member cb1 in arrlist)
{
cb[k] = cb1;
k++;
}
for (int i = 0; i < arrlist.Count; i++)
{
for (int j = 0; j < arrlist.Count; j++)
{
if (cb[i].salary() > cb[j].salary())
{
temp = cb[i];
cb[i] = cb[j];
cb[j] = temp;
}
else if (cb[i].salary() == cb[j].salary())
{
if (string.Compare(cb[i].name, cb[j].name) == -1)
{
temp = cb[i];
cb[i] = cb[j];
cb[j] = temp;
}
}
}
}
foreach (Member canbo in cb)
{
Console.WriteLine("Full name : " + canbo.name + "\tSalary : " + canbo.salary().ToString());
}
}

static void Main(string[] args)// make menu


{
int temp;
ArrayList AlList = new ArrayList();
ArrayList AlistMember = new ArrayList();
do
{
Console.WriteLine("--Salary management program--");
Console.WriteLine(" 1. Input data ");
Console.WriteLine(" 2. Shearch ");
Console.WriteLine(" 3. Sort by salary and dissplay all");
Console.WriteLine(" 4. Exit");
Console.WriteLine(" please choose : ");
temp = Convert.ToInt32(Console.ReadLine());
switch (temp)
{
case 1:// input data
Console.Clear();
int m;
Console.Write("enter number of: ");
m = int.Parse(Console.ReadLine());
Member[] cb;
cb = new Member[m];
for (int i = 0; i < m; i++)
{
CreatMember C_NV = new CreatMember(Member);
member nv = C_NV();
AlList.Add(nv);
AlistMember.Add(nv);
}
break;
case 2:// find information
Console.Clear();
int tam = 0;
bool check = false;
int count = 0;
Console.WriteLine("1. Search by name 2. Search by department \nEnter number: ");
tam = Convert.ToInt32(Console.ReadLine());
if (tam == 1)
{
string name;
Console.WriteLine("Enter name :");
name = Console.ReadLine();
foreach (member nv in AlistMember)
{
check = nv.SearchName(name);
if (check == true) count++;
}
if (count == 0) Console.WriteLine("Name does not exist");
}
else if (tam == 2)
{
string name;
Console.WriteLine("Enter department :");
name = Console.ReadLine();
foreach (member nv in AlistMember)
{
check = nv.SearchDepartment(name);
if (check == true) count++;
}
if (count == 0) Console.WriteLine(" Does not exist");
}
break;
case 3:
{
Console.Clear();
display display = new display(Display);
display(AlList);
break;
}
case 4: break;
}
}
while (temp <= 4);
}
}
abstract class Member// update Money allowance, Payroll and display in case 2
{
public string name { get; set; }
public int Salary { get; set; }
public int c { get; set; }
public int b { get; set; }
public abstract int salary();
public abstract void Updatec();
}
class member : Member
{
public string department { get; set; }
public int a { get; set; }
public string Position { get; set; }
public override void Updatec()
{// c in flowchart
if (Position == "Manager")
base.c = 2000000;
else if (Position == "Deputy")
base.c = 1000000;
else base.c = 500000;
}
public override int salary()
{
return (base.b * a + base.c);
}
public bool SearchName(string Name)
{
if (Name == base.name)
{
Console.WriteLine("===== Data =====");
Console.WriteLine("Full name : " + base.name);
Console.WriteLine("Department : " + department);
Console.WriteLine("Number day attendance : " + a);
Console.WriteLine("1 day's salary : " + base.b);
Console.WriteLine("Money allowance: " + base.c);
Console.WriteLine("Position : " + Position);
Console.WriteLine("Salary : " + salary().ToString());
return true;
}
return false;
}
public bool SearchDepartment(string Department)
{
if (Department == department)
{
Console.WriteLine("===== Data =====");
Console.WriteLine("Full name : " + base.name);
Console.WriteLine("Department : " + department);
Console.WriteLine("Number day attendance : " + a);
Console.WriteLine("1 day's salary : " + base.b);
Console.WriteLine("Money allowance: " + base.c);
Console.WriteLine("Position : " + Position);
Console.WriteLine("Salary : " + salary().ToString());
return true;
}
return false;
}
}
}

*. - Show important code:

int tam = 0;
bool check = false;
int count = 0;
Console.WriteLine("1. Search by name 2. Search by department \nEnter number: ");
tam = Convert.ToInt32(Console.ReadLine());
if (tam == 1)
{
string name;
Console.WriteLine("Enter name :");
name = Console.ReadLine();
foreach (member nv in AlistMember)
{
check = nv.SearchName(name);
if (check == true) count++;
}
if (count == 0) Console.WriteLine("Name does not exist");
}
else if (tam == 2)
{
string name;
Console.WriteLine("Enter department :");
name = Console.ReadLine();
foreach (member nv in AlistMember)
{
check = nv.SearchDepartment(name);
if (check == true) count++;
}
if (count == 0) Console.WriteLine(" Does not exist");

The code I used for find information with name or department. The first after input data and name want to find, the program will use
“bool check” to check the name in AlistMember. Then I make that scan data if name input is the same name in list, that true and print
to screen.

7.Test plan
Test key What is being How to test Data Expected Result Evaluate
test Result

1 Input menu Try to input 1,2,3,4 ok Valid input pass


boundary data,
typical data
and bad data
2 Input name Try to input abcdef ok Valid input pass
boundary data,
typical data
and bad data
3 Input Try to input 6, 6a, 14.5 ok Valid input pass
Department boundary data,
typical data
and bad data
4 Number day Try to input 1,2,3,4,5 ok Valid input pass
attendance boundary data,
typical data
and bad data
5 Number day Try to input -1,-2,-3 ok Valid input failed
attendance boundary data,
typical data
and bad data
6 Input number Try to input 1,2 ok Valid input pass
in mini menu boundary data,
typical data
and bad data

8. Comments and repairs in the future.

The software is not optimized

still have an import error

haven't tried catch

In the future will learn additional and optimization


9. References
1. documents of teacher Truong Cong Doan.

2. http://kcntt.duytan.edu.vn/Home/ArticleDetail/vn/173/2859/cac-dac-trung-cua-thuat-toan

3. https://sites.google.com/site/bai5tubaitoandenchuongtrinh/4-mot-so-vi-du-ve-thuat-toan

4. https://www.google.com/

You might also like