Mohammad Ali Jinnah University - Mechanical Engineering - Computer Programming - Assignment 7 - Practice Problems, Exercises of Computer Numerical Control

Computer programming Assignment

Typology: Exercises

2011/2012

Uploaded on 06/22/2012

armalik
armalik 🇵🇰

7 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Practice Problems
Deadline: Friday, December 9, 2011
1. Write a program that generates the following output:
This is my first program in Visual C++
“This is my first program in Visual C++”
This \ is \ my \ first \ program \ in \ Visual \ C++ \
2. What will be the output when the following line of code is executed:
cout << “This is how\t\bEscape Sequences\b work\r*”;
3. Write a program that accepts an integer from the user. Compute the square and
cube of that number. The output should look something like this:
Enter an integer: 10
10‟s square is 100
10‟s cube is 1000
4. Write a program that accepts 5 integers from the user and computes their sum and
average.
Enter the first number: 1
pf3
pf4

Partial preview of the text

Download Mohammad Ali Jinnah University - Mechanical Engineering - Computer Programming - Assignment 7 - Practice Problems and more Exercises Computer Numerical Control in PDF only on Docsity!

Practice Problems

Deadline: Friday, December 9, 2011

1. Write a program that generates the following output:

This is my first program in Visual C++

“This is my first program in Visual C++”

This \ is \ my \ first \ program \ in \ Visual \ C++ \

2. What will be the output when the following line of code is executed:

cout << “This is how\t\bEscape Sequences\b work\r*”;

3. Write a program that accepts an integer from the user. Compute the square and cube of that number. The output should look something like this:

Enter an integer: 10

10‟s square is 100

10‟s cube is 1000

4. Write a program that accepts 5 integers from the user and computes their sum and average.

Enter the first number: 1

Enter the second number: 10

Enter the third number: -

Enter the fourth number: 20

Enter the fifth number: 4

The Sum of these numbers is 25

The Average of these numbers is 5

5. What is wrong with the following programs:

 #include <iostream.h>

int main (int argc, char* argv[])

{

cout << “This is my first program”;

}

 #include <iostream.h>

int main (int argc, char*argv[])

{

cout >> “Hello World!”;

return 0;

}

________________

_______ main(__________)

{

____ << I have saved my file at ____MyFile << endl;

_________ ;

}

The program is supposed to display this message “I have saved my file at D:\MyFile\”

8. Write a program that asks the user to enter „n‟ numbers and displays their sum and average at the end. („n‟ is any real number greater than or equal to 2). Use a for- loop to solve this question. For-loops have been explained in the „Pre-lab‟ posted on **this website.

  1. Write a program that accepts an integer from the user and determines whether it is** „even‟ or „odd‟.