Different ways to represent a birthday register

Assignment Help C/C++ Programming
Reference no: EM13811411

Question 1: The following code is meant to find the largest item of a list, but the lines are out of order. The following code is meant to define such a function, but the lines are out of order. In your answer put the line numbers in the correct order and introduce appropriate indentation (indent the line numbers to show how the corresponding lines would be indented in your code). Do not write the entire corrected program in your answer.

1 if number > largest:

2 numbers = [3, 5, 2, 1, 4]

3 print largest

4 largest = number

5 for number in numbers:

6 largest = 0

Question 2 : Describe two different ways to represent a birthday register, i.e. the names of your friends and their birth dates. Assume that none of your friends have the same name, but that it is possible for two or more of them to share the same birthday. Do not represent the date as a string. Show how the following data would be represented in both models.

2/Jan Asimov

3/Jan Tolkien

18/July Mandela

18/July Branson

Question 3: Explain the purpose of the following code:

d = {}

for x in open("data.txt").read().split():

if x not in d:

d[x] = 0

d[x] += 1

Question 4: Consider the following code: 1. signFlag = False

2. evenFlag = False

3. inputstr = raw_input("Enter two numbers: ")

4. num1 = int(inputstr.split(", ")[0])

5. num2 = int(inputstr.split(", ")[1])

6. if num1 < 0 and num2 = 0 and num2 >= 0:

10. sign = 'positive'

11. signFlag = True

12. if num1%2 == 0 and num2%2 == 0:

13. num = 'even'

14. evenFlag = True

15. if num1%2 != 0 and num2%2 != 0:

16. num = 'odd'

17. evenFlag = True

18. if signFlag and evenFlag:

19. print num1, 'and', num2, 'are both', sign, 'and', num

20. elif signFlag:

21. print num1, 'and', num2, 'are both', sign

22. elif evenFlag:

23. print num1, 'and', num2, 'are both', num

24. else:

25. print num1, 'and', num2, 'have nothing in common'

--Assume that the input is "-12, 14". Using the given line numbers in this code (at the far left of the listing) list the order (by writing down the line number order) that the code will be executed.

--What is the output for the input "-12, -14"?

--What is the output for the input "-3, 9"?

--Explain in detail what the program does.

Question 5: Write a function file_length(filename) which takes the name of a file as its only parameter, and returns an integer specifying the number of lines in the file.

Question 6: Write a function middleReverse() that takes a lowercase string as an argument and returns a lowercase string that is the reverse of the original string except for the first and last letter. You may not use the method reverse().

Examples:

The call middleReverse('a') returns 'a'.

The call middleReverse('at') returns 'at'.

The call middleReverse('excitement') returns 'enemeticxt'. The call middleReverse('racecar') returns 'racecar'.

Reference no: EM13811411

Questions Cloud

What is the companys new required rate of return : Mikkelson Corporation's stock had a required return of 11.75% last year, when the risk-free rate was 5.50% and the market risk premium was 4.75%. Then an increase in investor risk aversion caused the market risk premium to rise by 2%. The risk-free r..
Roles and responsibilities and deliverables : Identify three TQM tools that may be used for ongoing process improvement. Be sure to describe who will use the tool, when it will be used, and what interval and how it will lead to process improvement.
Analyze the performance of timco : Analyze the performance of Timco. This year: ATO=1.4, GPM=.26, EM=1.8, Interest Retention=.81, Tax Retention=.66. Last year: ATO=1.2, GPM=.29, EM=1.6, Interest Retention=.84, Tax Retention=.69.
Increase or decrease-companys cash change : Increase or decrease. Based on the information below, by how much did the company’s cash change?
Different ways to represent a birthday register : Describe two different ways to represent a birthday register, i.e. the names of your friends and their birth dates. Assume that none of your friends have the same name, but that it is possible for two or more of them to share the same birthday
What is the companys equity price to book ratio : The company share price in the stock market is $42. The equity book value per share according to the balance sheet is $56. There are 540 million shares outstanding. What is the company’s equity price to book ratio?
What is an article review : What is an article review
Find the companys price-to-earnings ratio : Today the company announces net income equals $12 million. They have 30 million shares outstanding, and today’s share price is $68.21. Find the company’s price-to-earnings ratio.
What was the actual average annual percentage rate : In exactly 15 months a bill of $21,200 is due. Today you deposit money such that if the account earns a target rate of return of 8.90% per annum, compounded monthly, the bill is perfectly financed. No other deposits or withdrawals have been made. You..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write definitions of the functions to overload the operators

Write the definitions of the functions to overload the operators defined in parts a to c and write  a  test  program  that  tests  various  operations  on  the class rectangleType.

  Displays columns titled "name", "quantity", "price", value

Write a program that displays columns titled "Name", "Quantity", "Price", and "Value". The fourth column contains the result of multiplying each item's quantity by its price. In addition, the program should calculate and display the total value of th..

  Write a function named concatenate

If the function discovers that the number of cells in the large array is not large enough to hold all the numbers to be copied into it, then the function should return 0 to indicate failure.

  Reverses the characters in a character array

Write the function reverseit that reverses the characters in a character array. You must also write main that calls reverseit.

  Solution to the naur text-processing problem

Design and implement a solution to the Naur text-processing problem using the language specified by your instructor. Execute it against test data and record the number of faults you find and the cause of each fault

  Compute for the monthly billing of their customers

An electric company wants to compute for the monthly billing of their customers. the company charges P2.50 per kwh and utility tax of 3% of the current bill shall be added.

  Public transport fare ticketing system

Implement and test a public transport fare ticketing system.

  When constructors and destructors are called

Objects, constructors and destructors are called each time the objects Enter and leave scope and inherit parent class

  What is the relationship between inodes and vnodes

What is the relationship between inodes and vnodes - In a multi-level indexed file system that has 1K blocks what is the maximum file size if the i-nodes contain 8 direct entries, one single and one double indirect entry each?

  Write a function named smallest that receives three integer

Write a function named smallest that receives three integer arguments and returns the smallest of the three values.

  Reads a set of integers from file

The code in file "hw5-stree.cpp" reads a set of integers from file and inserts them into a binary search tree. You are asked to implement two functions max() and depth() that compute the maximum element and the depth of the binary search tree.

  Given the following test scores and grade equivalents

Given the following test scores and grade equivalents, write a function which is passed a score, and returns a letter grade based on the score entered. A number less than 0 or greater than 100 is invalid.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd