DEPARTMENT OF MECHANICAL ENGINEERING COLLEGE OF E&ME, NUST, RAWALPINDI Subject Name : FUNDAMENTALS OF PROGRAMMING II LAB REPORT # 13 SUBMITTED TO: Instructor Name : Sir Asad Mansoor SUBMITTED BY: Student Name: Maria Imran Reg # 477996 DE-45 - Dept ME Submission Date:20 – 5 - 24 Tasks: 1. Question statement : Make a GUI for a converter that takes a distance value in an Edit box and outputs the result in another Edit box. The GUI will have buttons to convert the entered value to the desired value. 1 kilometer = .621 miles, 1 mile = 1.61 kilometers Solution: var1=get(handles.edit1,'String'); to_mile=str2double(var1)*0.62; set(handles.edit1,'String',num2str(to_mile)); var2=get(handles.edit1,'String'); to_kilo=str2double(var2)/0.62; set(handles.edit1,'String',num2str(to_kilo)); File layout: Output: 2. Question statement: Create a GUI for a simple calculator that can perform the following operations: • Addition • Multiplication • Division • Subtraction All these functions are mapped to different buttons and the entered values are in different Edit Boxes. Solution: Changes in code of GUI : Function for subtraction : var4=get(handles.edit1,'String'); var5=get(handles.edit2,'String'); subtraction=str2double(var4)-str2double(var5); set(handles.edit4,'String',num2str(subtraction)); Function for addition: var3=get(handles.edit1,'String'); var4=get(handles.edit2,'String'); addition=str2double(var3)+str2double(var4); set(handles.edit4,'String',num2str(addition)); Function for division : var5=get(handles.edit1,'String'); var6=get(handles.edit2,'String'); division=str2double(var5)/str2double(var6); set(handles.edit4,'String',num2str(division)); Function for multiplication: var8=get(handles.edit1,'String'); var7=get(handles.edit2,'String'); multiplication=str2double(var8)*str2double(var7); set(handles.edit4,'String',num2str(multiplication)); File layout: Output: 3. Question statement: Modify Task 2 to make the calculator a scientific one. You can add functions like sin, tan, cos, square root etc. Add as many functions as you like to this calculator. Solution: Function for sin : var7=get(handles.edit1,'String'); sin_of_var=sin(str2double(var7)); set(handles.edit1,'String',num2str(sin_of_var)); Function for cos: var7=get(handles.edit1,'String'); cos_of_var=cos(str2double(var7)); set(handles.edit1,'String',num2str(cos_of_var)); Function for tan : var7=get(handles.edit1,'String'); tan_of_var=tan(str2double(var7)); set(handles.edit1,'String',num2str(tan_of_var)); Function for mod: var7=get(handles.edit1,'String'); tan_of_var=tan(str2double(var7)); set(handles.edit1,'String',num2str(tan_of_var)); File layout: Output: Performing modulus: