Programming Fundamentals Assignment Solutions: C++ Basics, Assignments of Java Programming

These assgnemets are are about java, RWS and islamiat

Typology: Assignments

2019/2020

Uploaded on 11/22/2020

zubaib-shahid
zubaib-shahid 🇵🇰

5

(1)

2 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Submitted To : Sir Shafique Ahmed
Submitted By : M. Zubaib Shahid
Registration # : SP19-BCS-061
Subject: Programming Fundamentals
Date : 06-03-2019
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Programming Fundamentals Assignment Solutions: C++ Basics and more Assignments Java Programming in PDF only on Docsity!

 Submitted To : Sir Shafique Ahmed

 Submitted By : M. Zubaib Shahid

 Registration # : SP19-BCS-

 Subject: Programming Fundamentals

 Date : 06-03-

If you want the user to input an integer value into your program for a variable named number, what are two lines of code you could write to ask the user to do it and to input the value into yourwhat are two lines of code you could write to ask the user to do it and to input the value into yo

ASSIGNMENT # 02

1. If you want the user to input an integer value into your program for a

variable named number, what are two lines of code you could write to ask

the user to do it and to input the value into your program?

Answer:

cout<<”Enter the integer value:”;

Cin>>number;

2. What is \n called and what purpose does it serve?

Answer:

In C++ a term called escape sequence. \n is a type escape sequence which is used to

create new line in the program. \n always write in double quotations in the program. We can

also use endl instead of \n.

e.g. cout<<”Zubaib”<<”\n”;

3. How would you write?

Cout<< "Hello, ";

cout << first_ name;

cout << "!\n";

as a single line of code?

Answer:

etc.

Question#5: What kind of literals are there?

Answer:

There are many types of literals.

1) Integer literals.

2) Floating-point literals.

3) Boolean literals.

4) Character literals.

5) String literals.

Question#6: What effect do tab, space and new lines have on program?

Answer:

Space is a escape sequence is use to give space between two words. “ends” is used to

give space.

Tab is also a escape sequence is used to give a horizontal tab in the program. We use \t

to give the tab.

e.g. cout<<”Zubaib ”<<ends<<”Shahid”;

New line is also a escape sequence is used to move on the next line. We use “endl” to move the

cursor to the next line.

e.g. cout<<”Zubaib”<<endl;

Question#7:What are the typical size of a char ,an int ,and a double?

Answer:

Char: 1 byte Int: 4 byte Double:

8 byte

Question#8: What measures do we use for the size of small entities in memory,

such as ints and strings?

Answer:

“BYTES” is the measures which we use for the size of small entities in memory.

Question#9: What is the difference between = and ==?

Answer:

= is the assignment operator which is used to assign the value to the variable.

e.g.

int z;

z=90;

on the other side

== is relational operator which is used to compare two value in the program.

e.g.

if(a==b)

Question#10: What is an initialization and how does it differ from an

assignment?

Answer:

Initialization mean at the time of deceleration we assign the value to the variable.

e.g.

int a=10;

whereas assignment operator is that in which when an initialized object is already

assigned a value from another existing object.

system("pause"); }

Output:

Question#13. Write a program that prompts the user to enter two integer

values. Store these values in int variables named val1 and val2. Write your

program to determine the smallest, largest, sum, difference, product, and ratio

of these values and report them to the user.

Answer:

#include using namespace std; void main() { cout << "Zubaib Shahid" << endl << "Registration no.:SP19-BCS-061" << endl << "SP19-BCS Section B " << endl << "......." << endl; int val1, val2; double sum, difference, product, ratio; cout << "Enter the value of val1:"; cin >> val1; cout << "Enter the value of val2:";

cin >> val2; if (val1 > val2) { cout << "The value " << val1 << " is largest"; cout << "The value " << val2 << " is smallest"; } else { cout << "The value " << val2 << " is largest"<<endl; cout << "The value " << val1 << " is smallest"<<endl; } sum = val1 + val2; cout <<"The sum of values is "<< sum << endl; difference = val1 - val2; cout <<"The difference of values is "<< difference << endl; product = val1*val2; cout <<"The product of values is "<< product << endl; ratio = val1 / val2; cout <<"The ratio of values is "<< ratio << endl; system("pause"); } Output:

Question#14:Modify the program above (Q13) to ask the user to enter floating-

point values and store them in double variables. Compare the outputs of the

two programs for some inputs of your choice. Are the results the same? Should

they be? What's the difference?

Answer:

#include

Question#15: Write a program to test an integer value to determine if it is odd

or even. As always, make sure your output is clear and complete. In other

words, don't just output “yes” or “no." Your output should stand alone, like

"The value 4 is an even number .".

Answer:

#include using namespace std; void main() { cout << "Zubaib Shahid" << endl << "Registration no.:SP19-BCS-061" << endl << "SP19-BCS Section B " << endl << "......" << endl; int a; cout << "Enter the value:"; cin >> a; if (a %2== 0) { cout << "The value " << a << " is even." << endl; } else cout << "The value " << a << " is odd." << endl; system("pause"); } Output:

Question#16: Write a program that generates the

following output:

Use an integer constant for the 10, an arithmetic

assignment operator to generate the 20, and a decrement

operator to generate the 19.

Answer:

#include using namespace std; void main() { cout << "Zubaib Shahid" << endl << "Registration no.:SP19-BCS-061" << endl << "SP19-BCS Section B " << endl << "........." << endl; int a; a = 10; cout << a<<endl; a +=10;

from user and draw the same table.

Answer(a):

#include using namespace std; void main() { cout << "Zubaib Shahid" << endl << "Registration no.:SP19-BCS-061" << endl << "SP19-BCS Section B " << endl << "........" << endl; cout << "Year\tResult\n------------\n1990\t135\n1991\t7290\n1992
t11300\n1993\t16200\n"; system("pause"); }

Output:

Answer(b):

#include using namespace std; void main() { cout << "Zubaib Shahid" << endl << "Registration no.:SP19-BCS-061" << endl << "SP19-BCS Section B " << endl << "......." << endl; int a1, b1, c1, d1, a2, b2, c2, d2; cout << "Enter four years" << endl; cin >> a1 >> b1 >> c1 >> d1; cout << "Enter results" << endl; cin >> a2 >> b2 >> c2 >> d2; cout << "Year\tresult" << endl << "................." << endl << a << "\t" << a2 << endl << b1 << "\t" << b2 << "\t" << endl << c1 << "\t" << c2 << endl << d1 << "\t" << d2<<endl; system("pause"); }

Output: