6 Pages

Java & C++ Examples

Course: FACULTY OF WXGE6320, Winter 2009
School: University of Malaya
Rating:
 
 
 
 
 

Word Count: 1083

Document Preview

// CardLayout.java This program displays a customer's personal information in a business card public class CardLayout { public static void main(String[] args) { int count; // count is a counter for printing "*" 50 times // Printing spaces in the top System.out.println("\n\n\n\n\n "); System.out.print("\t"); // Printing first line of the design for ( count=1 ;...

Register Now

Unformatted Document Excerpt

Coursehero >> Other International >> University of Malaya >> FACULTY OF WXGE6320

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
// CardLayout.java This program displays a customer's personal information in a business card public class CardLayout { public static void main(String[] args) { int count; // count is a counter for printing "*" 50 times // Printing spaces in the top System.out.println("\n\n\n\n\n "); System.out.print("\t"); // Printing first line of the design for ( count=1 ; count<50; ++count) System.out.print("*"); // Printing the information System.out.println(" "); System.out.println("\t*\t\t\t\t\t\t*"); // using "\t" for printing 7 spaces System.out.println("\t*\t\t\t\t\t\t*"); System.out.println("\t*\t\t================\t\t*"); System.out.println("\t*\t\tBhfjhfkfkjkgkjkj\t\t*"); System.out.println("\t*\t\t================\t\t*"); System.out.println("\t*\t Home Tel. 03-435345435\t\t*"); System.out.println("\t*\t Work Tel. 03-454354455\t\t*"); System.out.println("\t*\t\t\t\t\t\t*"); System.out.println("\t*\t\t\t\t\t\t*"); System.out.println("\t*\t\t\t\t\t\t*"); System.out.println("\t*\t\t\t\t\t\t*"); System.out.println("\t* jkdfhjkdfhjkdfkjdfkgkdjf\t\t\t*"); System.out.println("\t* Wangsa Maju, Section 10\t\t\t*"); System.out.println("\t* 53300 Kuala Lumpur\t\t\t\t*"); System.out.println("\t*\t\t\t\t\t\t*"); System.out.print("\t"); for (count=1 ; count<50; ++count) System.out.print("*"); System.out.println("\n\n\n\n\n "); } } Question 1 The constant percentage method of computing depreciation of an asset is based on the assumption that the depreciation charge at the end of each year is a fixed percentage of the book value of the asset at the beginning of the year. This assumption leads to the following relationship: S = C (1 - d ) n where C = original cost of asset d = depreciation rate per year n = number of years S = book value at the end of n years Write a program to compute the number of years of useful life of an asset given the original cost, depreciation rate, and book value at the end of its useful life. As input, the program is to read the data from the keyboard. Prompt the user to enter the data in the following way: Enter the original cost and depreciation rate: .......... Enter the book value at the end of the useful life of an asset: ......... Print the result to the screen as follows: The useful life of the asset is: .... Years Question 2 Use the statement cout<<"*"; and loops and if control structures as needed to print the form of stars: ********** * * * **** * * * * * * **** * * * ********** Question 3 Create a base class named Book. Data fields include title and author; functions include those that can set and display the fields. Derive two classes from the Book class; Fiction, which also contains a numeric grade reading level, and NonFiction, which contains a variable to hold the number of pages. The functions that set and display data fields values for the subclasses should call the appropriate parent class functions to set and display the common fields, and include specific code pertaining to the new subclass fields. Write a main() function that demonstrates the use of the classes and their functions. Question 4 Create a Painting class that holds the painting title, artist name, and value. All Paintings are valued at RM400 unless they are FamousPaintings. FamousPainting The subclass overrides the Painting value and sets each Painting's value to RM25000. Write a main() function that declares an array of 10 Painting objects. Prompt the user to enter the title and artist for each of the 10 Paintings. Consider the Painting to be a FamousPainting, if the artist is one the following: Degas, Monet, Picasso, or Rembrandt. Display the 10 Paintings. Question 5 Glad To Meet You is a company that designs and prints personal business cards. The company has asked you to write a Java application to display the layout of the information in a typical business card order. Data items in a typical business card include the customer's name, address, city, state, postcode, home phone number, and work phone number. Write, compile and test a Java class that displays these data items in an attractive layout on the console screen, using your own name and other personal information. Be certain to include appropriate comments in your class. Save the class as CardLayout.java in the Chapter01 folder on your disk. Question 6 Travel Tickets Company sells tickets for airlines, tours, and other travel related services. Because ticket agents frequently mistype long ticket numbers, Travel Tickets has asked you to write an application that will indicate if a ticket number entry is invalid. The class displays an input dialog box that prompts a ticket agent to enter a six digit ticket number. Ticket numbers are designed so that if you drop the last digit of the number, then divide the number by 7, the remainder of the division will be identical to the last dropped digit. This process is illustrated in the following example: Step 1 Step 2 Step 3 Step 4 remainder Step 5 Enter the ticket number, for example 123454 Remove the last digit, leaving 12345 Determine the remainder when the ticket number is divided by 7. In this case, 12345 divided by 7 leaves a remainder of 4. Assign the Boolean value of the comparison between the and the digit dropped from the ticket number. Display the result true or false in a message box. Test the application with these ticket numbers: 123454, 147103, and 154123. Save the case as TicketNumber.java in the Chapter2 folder on your disk. 1) get square root of one number #include<iostream.h> #include<math.h> void main() { int x; rootsq r; cout<<"Enter x.."; r=sqrt(x); cout<<r; } 2) get the answer of this equation f(x)=x*2 + 2x + 1 Where x can be any number #include<iostream.h> void main() { int f; int x; cout<<"Enter x.."; cin>>x; f=x*2 + 2*x + 1; cout<<"f(x) = "<<f; Q1- get square root of one number Q2- get the answer of this equation f(x)=x*2 + 2x + 1 WHERE x CAN BE ANY NUMBER 1) sqrt(64); 2) #include <stdio.h> int main() { int x = 0; printf("Enter A number : "); scanf("%i",&x); printf("f(x) = %i",(x * 2) + (2 * 0x) + 1); return 0; } #include <iostream.h> void main() { int x; int f;{ f(x)} cout<< "enter the value of x";{ } cin>>x; { x} f=(x*x)+(2*x)+1 cout <<"write"<<x<<"can be any number; } #include<iostream.h> : #include<math.h> void main() { int x=4;float r; r=sqrt(x); cout<<r; } : #include<iostream.h> : void main() { int f; int x; cout<<"Enter x.."; cin>>x; f=x*2 + 2*x + 1; cout<<"f(x) = "<<f; }
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Malaya - FACULTY OF - WXGE6320
Chapter 7 - JavaScript: Introduction to ScriptingOutline7.1 7.2 7.3 7.4 7.5 7.6 7.7 Introduction Simple Program: Printing a Line of Text in a Web Page Obtaining User Input with prompt Dialogs 7.3.1 Dynamic Welcome Page 7.3.2 Adding Integers Memory Conce
University of Malaya - FACULTY OF - WXGE6320
Chapter 8 - JavaScript: Control Statements IOutline8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 Introduction Algorithms Pseudocode Control Structures if Selection Statement if.else Selection Statement while Repetition Statement Formulating Algorithms: Case Study 1 (
University of Malaya - FACULTY OF - WXGE6320
Chapter 9 - JavaScript: Control Statements IIOutline9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 9.10 9.11 Introduction Essentials of Counter-Controlled Repetition f o r Repetition Statement Examples Using the f o r Statement s w i t c h Multiple-Selection State
University of Malaya - FACULTY OF - WXGE6320
Chapter 10 - JavaScript: FunctionsOutline10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11 10.12 Introduction Program Modules in JavaScript ProgrammerDefined Functions Function Definitions RandomNumber Generation Example: Game of Chance Another E
University of Malaya - FACULTY OF - WXGE6320
Chapter 7 - JavaScript: Introduction to ScriptingOutline7.1 7.2 7.3 7.4 7.5 7.6 7.7 Introduction Simple Program: Printing a Line of Text in a Web Page Obtaining User Input with prompt Dialogs 7.3.1 Dynamic Welcome Page 7.3.2 Adding Integers Memory Conce
University of Malaya - FACULTY OF - WXGE6320
Markup LanguageQ1/ What is a markup language? Markup language is a set of codes or tags that surrounds content and tells a person or program what that content is (its structure) and/or what it should look like (its format). Markup tags have a distinct sy
University of Malaya - FACULTY OF - WXGE6320
Math Teacher Expert SystemIntroductionExpert Systems: are computer programs that are derived from the Artificial Intelligence. The obvious extension of storing knowledge inside a computer program is to make use of that knowledge to solve practical probl
University of Malaya - FACULTY OF - WXGE6320
phone A phone is a 'unit sound' of a language in the sense that it is the minimal sound by which two words can differ. For example, the English word feed contains three phones since each can be independently substituted to form a different word. In the IP
University of Malaya - FACULTY OF - WXGE6320
PHP Array Functions PHP Array Introduction The array functions allow you to manipulate arrays. PHP supports both simple and multi-dimensional arrays. There are also specific functions for populating arrays from database queries. Installation The array fun
University of Malaya - FACULTY OF - WXGE6320
Presentation DesignWRET1103Some key visual display principles (Lewis and Rieman, 1994)The `clustering' principleorganise screen into visually separate blocks based on logical grouping Aim to give title to each blockThe `visibility reflects usefulness
University of Malaya - FACULTY OF - WXGE6320
WRET3310: Quiz 1J XHTML, JavaScriptsAnswer ALL Questions If you manage to produce the requirement output, you'll get 1 mark. You have 45 minutes on this quiz. Spend 10 minutes on every questions. Save your work as .html files named after the question e
University of Malaya - FACULTY OF - WXGE6320
QUIZ 2 WEB APPLICATION DEVELOPMENT (40 Minutes) - 5% Answer All Questions 1. Answer True or False for each of the following statements:i) ii)iii) iv)v)vi) vii) viii) ix) x)The &lt;!ELEMENT list (item*)&gt; defines element list as containing one or more ite
University of Malaya - FACULTY OF - WXGE6320
WRET2101Representation and Description Representation &amp; DescriptionThe results of segmentation is a set of regions. Regions have then to be represented and described.RepresentationTwo main ways of representing a region:1. external characteristic
University of Malaya - FACULTY OF - WXGE6320
Fastest Route from CS Dept to Einstein's HouseShortest PathsDijkstra's algorithm Bellman-Ford algorithmPrinceton University COS 226 Algorithms and Data Structures Spring 2004 Kevin Wayne http:/www.Princeton.EDU/~cos2262Shortest Path ProblemShortest
University of Malaya - FACULTY OF - WXGE6320
Speech InterfaceSpeech Overview VoiceUser Interface How does it work? Synthesis(TTS) Recognition (SR)Speech Synthesis Textto Speechdatabase Dynamic PromptHow Speech Synthesis Works? Textparsingnumbers, symbols, pauses Sentences, Natural P
University of Malaya - FACULTY OF - WXGE6320
SynchronizationSynchronization Synchronizationmultimedia. People paying for the localization project do not want to have to re-shoot expensive video. Instead, they ask you to use the same characters, just put in a different sound. Unfortunately, if we
University of Malaya - FACULTY OF - WXGE6320
2007/2008 Tutorial 1 Answer Q1 : I) II) III) IV) Entities: Departments, Employees, Supervisor, Projects Assigned (Employee-Department), Has (Department-Supervisor), Works-On (Employee-Project), The only attributes indicated are the names of the department
University of Malaya - FACULTY OF - WXGE6320
Multimedia and Learning Tutorial 1: Discussion1. Richard Clark's nowfamous comment about the impact of computers on learning was that the best current evidence is that media are mere vehicles that deliver instruction but do not influence student achievem
University of Malaya - FACULTY OF - WXGE6320
Tutorial 1 answersQ1: I) II) III) IV) Entities: Departments, Employees, Supervisor, Projects Assigned (Employee-Department), Has (Department-Supervisor), Works-On (Employee-Project), The only attributes indicated are the names of the departments, project
University of Malaya - FACULTY OF - WXGE6320
Multimedia and Learning Tutorial 2: Planning and Implementation for Effective Technology Integration1. Assume you are a classroom teacher at a level and type of school of your choice. Describe how the school should go about developing a technology imple
University of Malaya - FACULTY OF - WXGE6320
Tutorial 2 1. A bank's system analyst has identified the data elements required to manage the Bank's safe deposit system. The data elements are: BoxHolder First Name Last Name Address City State PostCode Phone Number Deputy BoxHolder Same as BoxHolder Box
University of Malaya - FACULTY OF - WXGE6320
Tutorial 2 Answers Q1 : There is more than one solution for this question. In general, the solution is as follows: The Tables: BOXHOLDER BOX BOX HISTORY BOX HOLDER IC No ( Or BoxHolderNo.) First Name Last Name Address City State PostCode Phone Number BOX
University of Malaya - FACULTY OF - WXGE6320
Multimedia and Learning Tutorial 31. Describe how knowledge about learning theories or instructional models is applied in the following research work: a. Grigoriadou et el., (2001) INSPIRE: An Intelligent System for Personalized Instruction in a Remote
University of Malaya - FACULTY OF - WXGE6320
Tutorial 3 STUDENT table SID S100 S150 S200 S250 S300 S350 S400 S450 Name Ismail Muthusamy Maniam Abu Bakar Mariam Mary Jessica Lim Major Information Science Artificial Intelligence Software Engineering Information Science Artificial Intelligence Software
University of Malaya - FACULTY OF - WXGE6320
Relational Algebra Exercises STUDENT table SID S100 S150 S200 S250 S300 S350 S400 S450 Name Ismail Muthusamy Maniam Abu Bakar Mariam Mary Jessica Lim Major Information Science Artificial Intelligence Software Engineering Information Science Artificial Int
University of Malaya - FACULTY OF - WXGE6320
Relational Algebra1.Consider the following AIRLINE database schema that describes the database for airline flight information: AIRPORT (Airport-code, Name, City) FLIGHT (Number, Airline, Weekdays) FLIGHT_LEG (Flight-number, Leg-number, Departure-airport-
University of Malaya - FACULTY OF - WXGE6320
Exercise II1.Consider the following AIRLINE database schema that describes the database for airline flight information: AIRPORT (Airport-code, Name, City) FLIGHT (Number, Airline, Weekdays) FLIGHT_LEG (Flight-number, Leg-number, Departure-airport-code Sc
University of Malaya - FACULTY OF - WXGE6320
Information VisualizationPart One1Introduction Thereare some aspects that may be understood better from graphics than from the textual format, such as the possibility for finding an alternative route, or the existence of historical places in the vici
University of Malaya - FACULTY OF - WXGE6320
Virtual Reality Markup Language (2) Understanding Shape AppearanceRecall that Shape nodes describe: Appearance nodes describe: Shape cfw_ geometry . . . appearance . . . geometry form, or structure appearance color and texture Shape cfw_ ap
University of Malaya - FACULTY OF - WXGE6320
VRML Script Node and JAVAWhy would you want to use Java with your VRML? Java class has more flexibility to define complex behaviors Java has its simple networking classes create multi-user VRML worlds, visualizations of the Internet or visualizations o
University of Malaya - FACULTY OF - WXGE6320
Virtual Reality Markup LanguageAn Introduction to VRML &amp; Modeling Shapes, Geometry, Colour Introduction The Virtual Reality Modeling Language A file format for describing interactive threedimensional objects and worlds (a model of a 3D space, which
University of Malaya - FACULTY OF - WXGE6320
WXGE6320: Web Application Tutorial 31. Develop a JavaScript program that will determine whether a department-store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: a. b. c. d. e. Account nu
University of Malaya - FACULTY OF - WXGE6320
WXGE6320: Web Application Tutorial 5Write a complete JavaScript program to request user for the radius of a sphere, and call function sphereVolume to calculate and display the volume of the sphere. Use the statement volume = (4.0 / 3.0) * Math.PI * Math.
University of Malaya - FACULTY OF - WXGE6320
WXGE6320: WEB DEVELOPMENT Tutorial 4 Answer All Questions 1. Draw a flowchart for selection statement below. Document.writeln( studentGrade &gt;= 70 ? &quot;Passed&quot; : &quot;Failed&quot;); 2. Write a JavaScript function to validate the username and password entered by a use
University of Malaya - FACULTY OF - WXGE6320
Tutorial 02 Carrier Sense Multiple Access (CSMA)1IntroductionIn the IEEE 802 protocols for shared multi-access LANs, the data link layer is divided into two sub layers, as shown next. The upper LLC (Logical Link Control) layer provides a way to address
University of Malaya - FACULTY OF - WXGE6320
Writing PapersStudents too often put off a written assignment, considering it a chore too formidable to approach until the last minute. As a result, grades inevitably suffer. Writing is not a talent reserved for a select few, it is a skill that can be le
University of Malaya - FACULTY OF - WXGE6320
Group Assignment 1 : Bellman-Ford's Algorithm and Applications to the Network Routing Theory Chapter 1 : Introduction a) Introduction to Algorithm : An algorithm is a type of effective method in which a systematic list of a known set of instructions for c
University of Malaya - FACULTY OF - WXGE6320
Chapter 4 - Introduction to XHTML: Part 1Outline 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 4.11 Introduction Editing XHTML First XHTML Example W3C XHTML Validation Service Headers Linking Images Special Characters and More Line Breaks Unordered Lists Nest
University of Malaya - FACULTY OF - WXGE6320
Chapter 5 - Introduction to XHTML: Part 2Outline5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 Introduction Basic XHTML Tables Intermediate XHTML Tables and Formatting Basic XHTML Forms More Complex XHTML Forms Internal Linking Creating and Using Image M
Harvard - ECON1723 - 312
1. Which of the following illustrates the concept of external cost? a. Margaret purchases all her food and clothing in the big city outside her residence. b. A small business owner frequently buys raw materials by using her bank's line of credit. *c. Raym
Harvard - ECON1723 - 312
1. Which of the following illustrates the concept of external cost? a) Margaret purchases all her food and clothing in the big city outside her residence. b) A small business owner frequently buys raw materials by using her bank's line of credit. c) Raymo
Harvard - ECON1723 - 312
ECON 102 Professor Jose J Vazquez Exam-3 FORM A2011Please choose the best answer. For all questions, only consider the change(s) implied by the question while holding &quot;all other things equal&quot;. PLEASE READ ALL QUSTIONS CAREFULLY; MANY OF THEM ARE NOT EXA
Ryerson - ECONMICS - 801
Time Value of Money and Economic EquivalenceChapter 3 Contemporary Engineering Economics Third Canadian Edition Copyright 2012 2012 Pearson Canada Inc., Toronto, Ontario1Chapter Opening Story: Take a Lump Sum or Annual Installments Millionaire Life i
Ryerson - ECONMICS - 801
Time Value of Money and Economic EquivalenceChapter 3 Contemporary Engineering Economics Third Canadian Edition Copyright 2012 2012 Pearson Canada Inc., Toronto, Ontario1Chapter Opening Story: Take a Lump Sum or Annual Installments Millionaire Life i
Ryerson - ECONMICS - 801
Debt Management Lecture No. 8 Chapter 4 Contemporary Engineering Economics Third Canadian Edition Copyright 2012 2012 Pearson Canada Inc., Toronto, Ontario1Lecture 10 ObjectivesHow are commercial loans and mortgages structured in terms of interest an
Ryerson - ECONMICS - 801
Simple Harmonic MotionPART I: POSITION AND VELOCITY IN SHMLots of things vibrate or oscillate. A vibrating tuning fork, a moving child's playground swing, and the loudspeaker in a radio are all examples of physical vibrations. There are also electrical
Ryerson - ECONMICS - 801
Ryerson - ECN - 801
Engineering Economic DecisionsChapter 1 Contemporary Engineering Economics Third Canadian Edition Copyright 2012 2012 Pearson Canada Inc., Toronto, Ontario1A Little Google History1995 Developed in dorm room of Larry Page and Sergey Brin, graduate s
Ryerson - PHYSICS - 125
ECN801, V. Bardis Sample Test 21. Suppose a bank charges a 16% semiannual rate, compounded quartely. (a) (3 marks) What is the nominal annual rate? What is the nominal quarterly rate?r_1 = 2 (16%) = 32% r_4 = (2/4) r_2 = 8% or r_4 = (1/4)r_1 = 8%(b) (3
Ryerson - PHYSICS - 125
Ry eH ub .C oMRy eH ub .C oMRy eH ub .C oMRy eH ub .C oMRy eH ub .C oMRy eH ub .C oMRy eH ub .C oMRy eH ub .C oMRy eH ub .C oMRy eH ub .C oMRy eH ub .C oM
Ryerson - PHYSICS - 125
(1)Giventhreeresistors Rr = 40 Q rated0.5 W Rz= 20 O rated1.5 W Rs= 10 O rated1.0W+(.(a) \Mat is the largestvoltageV, that can be safelyapplied the series combination these to of threeresistors ? (b) Whatis the largestcurrentIt that can be safelypasse
Ryerson - PHYSICS - 125
ECN 801: PRINCIPLES OF ENGINEERING ECONOMICSContact Instructor: Office Hours: Email: Lecture: Course Description The objective of this course is to introduce basic concepts and ideas of engineering economics and to apply them to economically evaluate var
Ryerson - PHYSICS - 125
Ryerson - PHYSICS - 125
Ryerson - PHYSICS - 125
MTH 140TestII - Winter 2008 question) If /(r) : r@ + | find /&quot;(2). 1. (2 pts.) (multiple-choice Selectthe correctanswer. Irswsr'A) -+B ) 3f'r*l= f tlx+4i?-4= e (4*+Lir/'c) -?D ) ?E ) *+ f a r x t= e A D f t x t D - e t 4 =- a ( f u * t ; \- - 4 .
Ryerson - PHYSICS - 125
MTH 140FinalExam W 0? 1. (10pts.) (u).llfil( Sor^tiD)4A )Find the followinglimits. If a limit doesnot exist,explainwhy:,. 9r2-1-&quot;-$ 3r * It7/eo/o = /:'\*,nthk t '/e'r. Bx't-1 Bx+t) r+ 'Yt 3x+ L-ltftx-D= 3fZ)-L-2..a!&amp;22:t'flofi.tuaA 4ule(
Ryerson - PHYSICS - 125
Ryerson University Department of Mathematics MTH 140 Fall 2007 Test IILAST NAME: (Please print)FIRST NAME: (Please print)I.D. NUMBER:SIGNATURE:Date: November 2, 2007Duration: 1 hourVersion: 3BT824G-TR0952Prof. Ha: Prof. Kim: Prof. Tasic: Prof. Pas
Ryerson - PHYSICS - 125
A-PDF Image To PDF Demo. Purchase from www.A-PDF.com to remove the watermarkRyeHub.CoMRy eH ub .C oMRy eH ub .C oMRy eH ub .C oM
Ole Miss - ECON - 564
Copper is a soft and malleable compound that has a reddish-orange color. It is primary used as a conductor of heat and electricity, a building material, and a component of various metal alloys. Most copper is mined or extracted from large open pit mines i
South Carolina - ECON - 293
econ
South Carolina - ECON - 293