1. Assume that the aIDress of b[0] is 5200 in memory. What output would be produced by the following program (if the output is an aIDress, you need to write out the exact aIDress. For example, the aIDress of b[1] is 5214)?
#include <iostream>
using std::cout;
using std::endl;
int main()
{
int b[] = {3,4,2,5,6,7};
int *xPtr;
xPtr = &b[2];
cout << xPtr << endl;
cout << *xPtr << endl;
cout << &b[3] << endl;
cout << b[4] << endl;
*xPtr = 9;
cout << *xPtr << endl;
return 0;
}
2 What is the output of the following program? Explain how the function leftShift shown below works and why we need the variable temp? (Hint: if you dont understand what the program do, please run it and print out what the value of temp when the function is called).
#include <iostream>
using namespace std;
void leftShift(int *);
int main()
{
int a[] = {3, 6, 7, 9, 4, 5, 2, 4, 2, 1};
for (int i = 1; i < 5; i++)
{
cout << Step << i << :n;
leftShift(a);
}
return 0;
}
void leftShift(int *array)
{
int temp = *array;
for (int i = 0; i < 9; i++)
*(array+i) = *(array+i+1);
*(array+9) = temp;
for (int i = 0; i<10; i++)
cout << *(array+i) << ;
cout << endl;
}
3 Given the following definitions and assignments, what do these expressions evaluate to (assume each of the following problems is independent).
int a[] = {2, 4, 0, 3, 5, 9, 12, 6}, n;
int *aPtr = &a[3];
(a) n = *aPtr + 1; n = _____________
(b) n = *(aPtr + 2); n = _____________
(c) n = *(aPtr 2); n = _____________
(d) n = *(++aPtr); n = _____________
(e) n = (*aPtr); n =______________
(f) n = a[++(*aPtr )]; n =______________
4 Point out whether each of the following program segments is valid or invalid. If it is invalid, explain why. Assume the following declarations:
double a = 8.1, b = 2.5;
const double *aPtr = &a;
double * const bPtr = &b;
(a) *aPtr = &b;
(b) *aPtr = 6.5;
(c) aPtr = &b;
(d) aPtr = b;
(e) *bPtr = 3.4;
(f) bPtr = &a;
5 What is the output by the following program segment?
char x[ ] = Today is a nice day ;
char y[50], z[50];
strcpy(y, x);
cout << The string x is: << x
<< nThe string y is: << y << endl;
strncpy(z, x, 9);
z[9] = ?;
cout << The string z is: << z;
strcat(z, y);
cout << nThe string z is: << z
<< nThe length of z is: << strlen(z) << endl;
6 Given the class definition:
class Grade
{
public:
void setGrade(int r)
{
result = r;
}
int getGrade()
{
return result;
}
void printGrade()
{
cout << Your result is << result << endl;
}
private:
int result;
};
Write a main program to perform three tasks: (a) declare an object; (b) assign a value to the data member; (c) output the value.
Programming (hand in C++ code only)
7 Write a function that accepts a pointer to a string as an argument and returns the number of words contained in the string, that is, the function prototype is
int wordCount(char *);
If the string argument is it is a nice day the function should return 5. Demonstrate the function in a program that asks the user to input a string and then passes it to the function. (Hint: you need to use cin.getline() to receive the input string). The sample output is:
Enter a sentence: it is a nice day
The sentence has 5 words.
Dont use strtok function. You can assume that the sentence has no empty spaces at the beginning and at the end.
8 Write a program to prompt user to enter a password. A valid password must have at least 6 characters and must consist of at least one lower character (ASCII code 97-122), one capital character (ASCII code 65-90) and one digital number (ASCII code 49-57). If the user enter a password shorter than 6 characters, or no capital or lower or special character, output the error message and let the user try again. Then let the user enter the password again to verify whether the user has remembered the password. If the two entered passwords are not the same, output error message and try again. If verification is OK, output Your password is: password. Use do-while, break and continue to make your code efficient.
Sample output:
Enter your password (e to exit): abcd
Password must be at least six characters! Try again.
Enter your password (e to exit): abcdef
Password must be one lower or capital or digital number! Try again
Enter your password (e to exit): Abcde7
Re-enter your password: abcde7
Two passwords are different. Try again.
Enter your password (e to exit): Abcde7
Re-enter your password: Abcde7
Your password is: Abcde7
9 Define a class called Point which consists two private data x and y with double type and three public member functions: a constructor Point(), void setPoint(double, double), void printPoint(). In the function setPoint, you need to verify if the values of x and y are located between 0 and100. If not set the value to be 0.0. In the printPoint(), print the following message:
(x, y) = (XXX.X, XX.X)
where X is a digit. In your main program, use keyboard to input the values of x and y (one time is OK). Then call setPoint() and printPoint().
Why Work with Us
Top Quality and Well-Researched Papers
We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.
Professional and Experienced Academic Writers
We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.
Free Unlimited Revisions
If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.
Prompt Delivery and 100% Money-Back-Guarantee
All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.
Original & Confidential
We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.
24/7 Customer Support
Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Our Services
No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.
Essays
No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.
Admissions
Admission Essays & Business Writing Help
An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.
Reviews
Editing Support
Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.
Reviews
Revision Support
If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.