0% found this document useful (0 votes)
151 views5 pages

Task 9.1. Re-Write The Code After Fixing The Errors.: (Need To Submit Task 9.2 and Task 9.3 As A Part of Assignment 3)

Uploaded by

Tiến Dũng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views5 pages

Task 9.1. Re-Write The Code After Fixing The Errors.: (Need To Submit Task 9.2 and Task 9.3 As A Part of Assignment 3)

Uploaded by

Tiến Dũng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SWE200024 – Technical Software Development

Lab 9: (Need to submit Task 9.2 and Task 9.3 as a part of assignment 3)

Task 9.1. Re-write the code after fixing the errors.

#include<iostream>
using namespace std;

struct emp
{
char *surname;
int age;
float salary;
}

int main()
{
struct emp ricky;
struct emp *aPtr;
ricky.surname = "Peter";
ricky.age = 35;
ricky.salary = 2000.53;

aPtr = &ricky;

cout<<"Surname: " << ricky->surname<<"\n"<<"Age: "


<<ricky.age<<"\n"<<"Salary : "<<ricky.salary<<endl;

cout<<"Surname: "<<aPtr.surname<<"\n"<<"Age: "<<(*aPtr).age


<<"\n"<<"Salary: "<<aPtr->salary;
return 0;
}

Task 9.2 Use the following structure for this problem. (Need to submit this task as a part of
assignment 3)

struct company_detail
{
string company_id;
string company_name;
};
struct Emp
{
string emp_name;
string emp_id;
double salary;
struct company_detail cmp_detail;
};

©Copyright: 2018 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Week 9 Lab Page 1 of 5
SWE200024 – Technical Software Development

Declare an array called employee[5] of type struct Emp. Use


get_data() to read in values for the array, use print_data()to print out the array
elements, use get_salary () function to search the salary of an employee and use
get_average () function to calculate average salary of a particular company (use company
name for this).

//below function prototypes must be used


struct Emp get_data();
void print_data(struct Emp[], int);
double get_average(struct Emp*, int,string);
double get_salary(struct Emp[], string);

Enum - Introduction
An enumeration is a user-defined data type that consists of set of integers. To define an
enumeration, keyword enum is used.
Eg:
enum months {
JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
}; // end enum months
creates a new type, enum months, in which the identifiers are set to the integers 0 to 11,
respectively.

By default enumeration numbering starts from 0

enum months {
JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
}; // this number the months 1 to 12.

#include <iostream>
#include <cstdlib>
using namespace std;
enum week { sunday, monday, tuesday, wednesday, thursday, friday, saturday };
void lecture_unit(week day)
{
switch(day)
{
case monday:
cout<<"SWE20004\n";
break;
case tuesday:
cout<<"COS10009\n";
break;
/*
.
.
.
*/
case sunday:
©Copyright: 2018 Swinburne University of Technology CRICOS: 0011D TOID: 3059
Week 9 Lab Page 2 of 5
SWE200024 – Technical Software Development

cout<<"Holiday\n";
break;
}
}
int main()
{
int day;
cout<<"What is the day today? 0 - Sunday, 1 - Monday, 2 -Tuesday etc "<<endl;
cin>>day;
week today = static_cast<week>(day);
lecture_unit(today);
return 0;
}

Task 9.3 (Need to submit this task as a part of assignment 3)

Write a complete C++ program to create a music player.

Your program should read in several album names, each album has up to 5 tracks as
well as a genre.

First declare genre for the album as an enumeration with at least three entries. Then
declare an album structure that has five elements to hold the album name, genre, number
of tracks, name of those tracks and track location.

You can use the template given below, but highly recommended to use your own variable
names and enumeration list.

Declare a vector (user determines the number of albums at the runtime) of type album
to create database for album.

In main you should have four option:

Option 1: call a function add_album – it allows the user to enter the album details.

Option 2: call a function named print_all_album to print out the album details.

©Copyright: 2018 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Week 9 Lab Page 3 of 5
SWE200024 – Technical Software Development

Option 3: call a select_track_to_play function that allows the user to


choose an album and then a track to play. It should print out:

When the user selects a track to play your program must call an external program
to play the track.

Option 4: Quit

Screen shot continue in the next page, these screen shots are taken from a single run.

©Copyright: 2018 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Week 9 Lab Page 4 of 5
SWE200024 – Technical Software Development

©Copyright: 2018 Swinburne University of Technology CRICOS: 0011D TOID: 3059


Week 9 Lab Page 5 of 5

You might also like