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

4 pages
1000+Number of visits
Description
Computer programming Assignment
20 points
this document
Preview3 pages / 4

Practice Problems

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: -10

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;

}

 #include<iostream.h>

void main()

{

cout << “*” << \t << “***” << endl;

}

6. What will the following programs do:

 #include<iostream.h>

void main()

{

char symbol = „s‟;

cout << symbol << “ symbol” << endl;

}

 #include<iostream.h>

void main()

{

cout << “what will be \ displayed?” << endl;

}

7.Fill in the blanks in the following program.

________________

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

9. Write a program that accepts an integer from the user and determines whether it is

„even‟ or „odd‟.