Assignment Problems for Computer Science I | CPSC 220, Assignments of Computer Science

Material Type: Assignment; Class: Computer Science I; Subject: Computer Science; University: University of Mary Washington; Term: Spring 2006;

Typology: Assignments

Pre 2010

Uploaded on 08/13/2009

koofers-user-3zm
koofers-user-3zm 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. The integer and floating point types in C++ are considered to be
_________________ types.
a. simple b. address c. structured
2. The struct and union types in C++ are considered to be _________________ types.
a. simple b. address c. structured
3. Give the values of each of the following expressions
a. 27 + 8/5 -7
b. 27 + 8 %5 -7
c. 27 + 8.0/5 - 7
4. Suppose str1 and str2 are string variables and str1 = “You should start with logic” and
str2= “th”. What is the value of each of the following expressions.
a. str1.substr(10, 5);
b. str1.substr(str1.find(“logic”),3)
c. str1.substr(15,8).find(str2.substr(0,1)
5. Implement an int function that has three int parameters. The first is named hours, the
second minutes and the third seconds. The function returns the number of seconds
represented by the parameters. For example, if hours contains 2, minutes contains 20, and
seconds contains 12, the function should return 8412.
6. The following code segment is supposed to write out the odd numbers from 1 to 19.
What does it actually output? Change the code to work correctly.
number = 1;
while( number < 10 )
{
number ++;
cout << number*2 -1 << “ “;
}
pf2

Partial preview of the text

Download Assignment Problems for Computer Science I | CPSC 220 and more Assignments Computer Science in PDF only on Docsity!

  1. The integer and floating point types in C++ are considered to be _________________ types. a. simple b. address c. structured
  2. The struct and union types in C++ are considered to be _________________ types. a. simple b. address c. structured
  3. Give the values of each of the following expressions a. 27 + 8/5 - b. 27 + 8 %5 - c. 27 + 8.0/5 - 7
  4. Suppose str1 and str2 are string variables and str1 = “You should start with logic” and str2= “th”. What is the value of each of the following expressions. a. str1.substr(10, 5); b. str1.substr(str1.find(“logic”),3) c. str1.substr(15,8).find(str2.substr(0,1)
  5. Implement an int function that has three int parameters. The first is named hours, the second minutes and the third seconds. The function returns the number of seconds represented by the parameters. For example, if hours contains 2, minutes contains 20, and seconds contains 12, the function should return 8412.
  6. The following code segment is supposed to write out the odd numbers from 1 to 19. What does it actually output? Change the code to work correctly. number = 1; while( number < 10 ) { number ++; cout << number*2 -1 << “ “; }
  1. Suppose we have the following loop and the input is taken from a file containing these numbers 10 20 30 14 15 18 -5 10 20. What is the output? sum = 0; cin >> num; while ( sum < 100 ); { sum = sum + num; cin >> num; } cout << sum << endl; cout << num << endl; while (cin ) { cout << num << endl; cin >> num; }
  2. Suppose we have the following declarations struct Date { int dd; // represents the day int mm; // represents the month int yyyy; // represents the yeat } struct Employee { string name; startDate : Date; } Person eca; // variable for Ackermann and three functions specified as void getEmployee( Employee &p) /* Retrieves the name and start date for an employee and stores it in the argument /* associated with the parameter p. Date today( ); /* Returns the current date as a Date item double JDN (int month, int day, int year) /* Returns the Julian day number of the date passed through the parameters */ Now, suppose the statement getEmployee(eca); is executed and it retrieves the information about an employee named Ackermann who started work at the college on August 3, 1980. Write the statements necessary, declaring any variables you need to, to display the number of days that Ackermann has been employed here.