Docsity

Lab Report 1: Storing & Displaying Lipstick Records with Structures & Arrays, Study Guides, Projects, Research of Algorithms and Programming

Partial preview of the text

Download Lab Report 1: Storing & Displaying Lipstick Records with Structures & Arrays and more Study Guides, Projects, Research Algorithms and Programming in PDF only on Docsity!

FACULTY OF INFORMATION SCIENCES AND

ENGINEERING

ALGORITHM AND DATA STRUCTURE

(CCS10403)

SESSION: FEBRUARY 2021

Lab Report 1

TOPIC: STRUCTURE

PREPARED BY:

Name ID Number Programme

DURGASUANY MANIRAJA 012020070473 DCF

PREPARED FOR: MDM SAFWATI BT SEMAAIL @ ISMAIL

Task 1 Create a program to store a record using structure. You need to define one structure template with minimum 3 data members. In main function, declare five structure variables, then get input from user and store into the variable. Then your program will display the content of the structure on the screen output. Program Description Explain about your developed program Coding Paste your program here #include #include using namespace std; struct lipstick { char brand[10]; float price; int noofshades; }; int main() { lipstick Programming; lipstick statistics; cout<<"lipstick Description\n"; cout<<"--------------------------\n"; cout<<"Enter lipstick brand: "; cin>>ws; cin.getline(Programming.brand,30); cout<<"Enter lipstick price (RM): "; cin>>Programming.price; cout<<"Enter lipstick no of shades: "; cin>>Programming.noofshades; cout<<"Enter lipstick brand: "; cin>>ws; cin.getline(statistics.brand,30); cout<<"Enter lipstick price (RM): "; cin>>ws; cin>>statistics.price; cout<<"Enter lipstick no of shades: "; cin>>statistics.noofshades; cout<<"Enter lipstick brand: "; cin>>ws; cin.getline(statistics.brand,30); cout<<"Enter lipstick price (RM): "; cin>>ws; cin>>statistics.price;

Task 2 Use the structure definition in Task 1 to store 5 records using an array of structure with five elements. Get the data from user, store into the array, then display the output in table format. Program Description Explain about your developed program Coding Paste your program here #include #include using namespace std; struct lipstick { char lipstick[30]; float price; int noofpage; }; int main() { lipstick Record[5]; int index; cout<<"lipstick Information\n"; cout<<"--------------------------\n"; for(index=0; index<5; index++) { cout<<"Enter bodyshop: "; cin>>ws; cin.getline(Record[index].lipstick,30); cout<<"Enter lipstick price (RM65): "; cin>>Record[index].price; cout<<"Enter lipstick no of brand: "; cin>>Record[index].noofpage; cout<<endl; } cout<<"\n\nList of lipstick \n"; cout<<"---------------------------------------------------------------\n"; cout<<setw(30)<<left<<"lipstick"<<setw(15)<<left<<"Price(RM65)"<<setw(5)<<left<<"No Of Page
n"; cout<<"---------------------------------------------------------------\n"; for(index=0; index<5; index++) { cout<<setw(30)<<left<<Record[index].lipstick;

cout<<setw(15)<<left<<Record[index].price; cout<<setw(5)<<left<<Record[index].noofpage; } } Sample output

cin.getline(Record[index].lipname,30); cout<<"Enter Lipstick Shade: "; cin>>ws; cin.getline(Record[index].shade,30); cout<<"Enter Lipstick Finishing: "; cin>>ws; cin.getline(Record[index].finish,30); cout<<"Enter lipstick price (RM): "; cin>>Record[index].price; cout<<"Enter the shop name: "; cin>>ws; cin.getline(Record[index].lipstickshop.name,30); cout<<"Enter shop's email: "; cin>>ws; cin>>Record[index].lipstickshop.email; cout<<"Enter shop contact number: "; cin>>Record[index].lipstickshop.contactNo; cout<<endl; } cout<<"\n\nList of lipstick \n"; cout<<"---------------------------------------------------------------\n"; cout<<setw(30)<<left<<"bodyshop"<<setw(15)<<left<<"Price(RM)"<<setw(5)<<left<<"No Of lipstick\n"; cout<<"---------------------------------------------------------------\n"; for(index=0; index<5; index++) { cout<<setw(30)<<left<<Record[index].brand; cout<<setw(15)<<left<<Record[index].lipname; cout<<setw(5)<<left<<Record[index].shade; cout<<setw(5)<<left<<Record[index].finish; cout<<setw(5)<<left<<Record[index].price; cout<<setw(30)<<left<<Record[index].lipstickshop.name; cout<<setw(20)<<left<<Record[index].lipstickshop.email; cout<<left<<Record[index].lipstickshop.contactNo<<endl; } } Sample output