Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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'.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91381364
  • Price:- $60

Guranteed 36 Hours Delivery, In Price:- $60

Have any Question?


Related Questions in C/C++

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As