290 likes | 391 Views
Advanced Programming. Examples. Example. Create rectangle class that consists of the length and width with methods to initialize the members, calculate the perimeter of the rectangle, and calculate the area of the rectangle. Example. Create class account to save personal account for a bank.
E N D
Advanced Programming Examples
Example • Create rectangle class that consists of the length and width with methods to initialize the members, calculate the perimeter of the rectangle, and calculate the area of the rectangle.
Example • Create class account to save personal account for a bank. • The class has account# and balance data • The class has deposit( ), withdraw( ) and display_data( ) methods • The main class create some account for some persons (as input data)
Example • Write a 12-hour clock program that declares a clock class to store hours, minutes, seconds, A.M. and P.M. provide methods to perform the following tasks: • Set hours, minutes, seconds to 00:00:00 by default • Initialize hours, minutes, seconds, A.M. and P.M. from user entries • Allow the clock to tick by advancing the seconds by one and at the same time correcting the hours and minutes for a 12-hour clock value of AM or PM • Display the time in hours:minutes:seconds AM / PM format
Example Coffee shop need a program to computerize its inventory. The data will be Coffee name, price, amount in stock, reorder level, barcode, sell by date. The operations on coffee are: prepare to enter stock, Display coffee data, check reorder level, change price, sell coffee.
Example • Create a class Time that contains data members, hour, minute, second to store the time value, and sets hour, minute, second to zero, provide three methods for converting time to ( 24 hour ) and another one for converting time to (12 hour) and a function that sets the time to a certain value specified by three parameters
Example • Your city classifies a pollution index • less than 35 as “Pleasant”, • 35 through 60 as “Unpleasant”, • and above 60 as “Health Hazard.” • Display the correct description of the • pollution index value.
Write a program that calculates bills for 66 customers using methods of the Electricity company. There are 3 types of customers: residential (code R) , commercial (code C) , and Industrial (code I). - For a code R customer, the bill is $10 plus $0.05 for each kilowatt used. - For a code C customer, the bill is $1000 for the first 2000 kilowatt, and $0.005 for each additional kilowatt used. - For a code I customer, the bill is $1000 if he used less than 4000 kilowatt, $2000 if he used between 4000 and 10000 kilowatt, or $3000 if he used more than 10000 kilowatt. The inputs of the program should be the type of customer ( R, C or I) and the kilowatts used. The output should be the amount of money the customer has to pay.
Example In one university, it has a rule that at least 75% of student in each course must pass. This means that the pass mark for each course will differ. Write a program that will read 100 students’ marks and determine the pass mark.
A number of students are answering a questionnaire form that has 25 questions. Answer to each question is given as an integer number ranging from 1 to 5. Write a program that first reads the number of students that have left the fulfilled questionnaire. After that the programs reads answers so that first answers of the first student are entered starting from question 1 and ending to question 25. Answers of second student are then read in similar way. When all answers are entered the program finds out what are questions (if any) to which all students have given the same answer. Finally the program displays those questions (the question numbers).
Pascal’s triangle looks like this: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 The number in each cell of each row is the sum of the numbers in the two cells above it. Write a method Pascal (int rows ) to print Pascal's triangle with number of rows is row.
Construct C# console application to solve the following problem. A football team plays n games per year in its league. Given n and the scores of all of the games the team played this year (both the team’s score and its opponent’s score for each game), compute the team’s margin of victory in the games that it played (win = 3, tied = 1 and ignore lost).
PrintMonth( month, year ) January 1900 Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Example • Write a console application that generate 10 random numbers and stores them in an array and then finds out how many times each of these numbers occurs in this array
Example • The main voltage supplied by a substation is measured at hourly intervals over a 72-hour period, and a report made. Write a program to read in the 72 reading array and determine: • the mean voltage measured • the hours at which the recorded voltage varies from the mean by more than 10% • any adjacent hours when the change from one reading to the next is greater than 15% of the mean value
Example • We wish to solve the following problem using C#. given an array A, print all permutations of A (print all values of A in every possible order). For example, A contained the strings “apple”, “banana”, and “coconut”, the desired output is: • apple banana coconut • apple coconut banana • banana apple coconut • banana coconut apple • coconut apple banana • coconut banana apple
Example • A sensitive drug cannot sustain a change in temperature of more than 30o C in a 24-hour period. The temperatures are monitored and recorded every two hours. Write console application the laboratory technician can use once a day to determine whether or not to throw the drug away.
Write a program to calculate the total price of a certain purchase. There is a discount and shipping cost: • The discount rate is 15% and the shipping is 10.00 if purchase is over 1000.00. • Otherwise, the discount rate is 5% and the shipping is 7.00 pounds.
A factory has some workers and it divides its workers into three skill levels. Unskilled workers receive L.E. 8.15 per hour, semiskilled workers receive L.E. 12.55 an hour, and skilled workers L.E. 18.60 an hour. Write a program to calculate the worker’s weekly pay formatted to two decimal places. Your program input should consist of the hours worked and a skill level indicator for the worker. Then the wage should be displayed.
Programming Examples • Write a program to ask the user for the width and length of a piece of land and then tell him how many orange trees he can grow on it. Given that each orange tree requires 4 m2.
Write a program that reads 100 integer numbers, determines how many positive and negative values have been read, and computes the average of the input values.
A shop need to keep an inventory of its 100 items for sale. Write a console application to input the item code, price and quantity of each item. Then the program displays a neat table of all items (code, price and quantity) with two asterisks ** next to items whose price > 100 pounds, and one asterisk * next to items whose price is between 50 and 100 pounds.
A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (for example, 1980). However, since the introduction of the Gregorian calendar on October 15, 1582, a year is not a leap year if it is divisible by 100 (for example, 1900); however, it is a leap year if it is divisible by 400 (for example, 2000). Write a C Program that accepts an int argument called “year” and print out if the year is a leap year or not.
Example The Air Force has asked you to write a program to label aircrafts as military or civilian. Your program input is the plane’s speed and its estimated length. For planes traveling faster than 1100 km/hr, you will label those shorter than 52 m “military”, and longer as “Civilian”. For planes traveling less than 1100, you will issue an “aircraft unknown” statement.
Write a C program that reads in 30 integer numbers and then print out their sum and average
Write a program that reports the speed of the wind. The program input is 100 speed of wind: Wind speed Content Below 25 Not strong 25 - 38 Strong wind 39 - 54 Gale 55 - 72 Whole gale above 72 Hurricane
Create class account to save personal account for a bank with interest. • The class has account# and balance data • The class has deposit( ), withdraw( ), interest_earned {2% interest will be credited to account at end of each month if balance exceeds $10,000} and display_data( ) methods
Create a class Employee that should contain an instance variables Birthday, Startday, firstName and LastName. Members’ startday and birthday are references to Date object which contains instance variables month, day and year. Employee class provides two constructors: one that takes no arguments and another that takes necessary parameters, and it provides member methods: settingdate (in class Date) and displaydata which use message box to show the Employee information (in class Employee).
Write a car class that has the following fields: YearModel (int filed hold the car’s year model), Make (string field that hold the make of the car), and Speed (int field that holds car’s current speed). • The class has the following methods: constructor that accepts the car’s year model and make arguments and assign speed to 0, assign_data ( ) to set values for all fields of the class by user, accelerate ( ) which add 5 to the speed each time it is called, break () which subtract 5 from speed each time it is called, and display () to print out the car’s information. • Create two objects from this class and call accelerate and break methods five time for each and display the speed each time.