Programming Fundamentals: C++ Exercises for Beginners, Study Guides, Projects, Research of Programming Languages

Book Exercise Solution Chapter2 to Chapters5 All Exercise are Solved And 20 Program To assignment Example 1Program Marksheet 2Program find Volt

Typology: Study Guides, Projects, Research

2022/2023

Uploaded on 05/22/2023

ahad-ansari-1
ahad-ansari-1 🇵🇰

1 document

1 / 88

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Department of Software Engineering
Faculty Of Engineering & Technology
University Of Sindh
Class:BSSW Part 1(Morning)
Semester : First Semester
Course: Programming Fundamentals
Full Name: Abdul Ahad
Roll Number :2k23/SWE/3
Chapter :2
Exrcise :1
#include <iostream>
using namespace std;
int main()
{
double gallons, cubic_feet;
const double gallons_per_cubic_foot = 7.481;
cout << "Enter the number of gallons: ";
cin >> gallons;
cubic_feet = gallons / gallons_per_cubic_foot;
cout << gallons << " gallons is equivalent to " << cubic_feet << " cubic feet." <<
endl;
return 0;
}
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58

Partial preview of the text

Download Programming Fundamentals: C++ Exercises for Beginners and more Study Guides, Projects, Research Programming Languages in PDF only on Docsity!

Department of Software Engineering

Faculty Of Engineering & Technology

University Of Sindh

Class:BSSW Part 1(Morning)

Semester : First Semester

Course: Programming Fundamentals

Full Name: Abdul Ahad

Roll Number :2k23/SWE/

Chapter :

Exrcise :

#include using namespace std; int main() { double gallons, cubic_feet; const double gallons_per_cubic_foot = 7.481; cout << "Enter the number of gallons: "; cin >> gallons; cubic_feet = gallons / gallons_per_cubic_foot; cout << gallons << " gallons is equivalent to " << cubic_feet << " cubic feet." << endl; return 0; }

Output: Exrcise: #include using namespace std; int main() { cout << "1990\t135\n" << "1991\t7290\n" << "1992\t11300\n" << "1993\t16200\n"; return 0; } Output

Exercise:

#include using namespace std; int main() { const int num = 10; int result = num; cout << result << endl; result += 10; cout << result << endl

Exercise:

#include #include <ctype.h> using namespace std; int main() { char a; cout << "Enter a letter: "; cin >> a; if (islower(a)) { cout << "Nonzero (letter is lowercase)." << endl; } else { cout << "Zero (letter is uppercase)." << endl; } return 0; }

Output:

Exercise:

#include using namespace std; int main() { double dollars, pounds, francs, deutschemarks, yen; cout << "Enter an amount in U.S. dollars: $"; cin >> dollars; pounds = dollars / 1.487; francs = dollars / 0.172; deutschemarks = dollars / 0.584; yen = dollars / 0.00955; cout << "British pounds: \x9C" << pounds << endl; cout << "French francs: " << francs << " FRF" << endl; cout << "German deutschemarks: DM" << deutschemarks << endl; cout << "Japanese yen: " << yen << " \xA5" << endl; return 0; } Output:

using namespace std; int main() { int pop1 = 2425785, pop2 = 47, pop3 = 9761; cout << left << setw(15) << setfill('.') << "Location" << right << setw(12) << "Population" << endl << setw(15) << setfill('.') << "Portcity" << right << setw(12) << pop1 << endl << setw(15) << setfill('.') << "Hightown" << right << setw(12) << pop2 << endl << setw(15) << setfill('.') << "Lowville" << right << setw(12) << pop3 << endl; return 0; } output:

Exercise:

#include #include using namespace std; int main() { int a, b, c, d;

char dummychar; cout << "Enter first fraction: "; cin >> a >> dummychar >> b; cout << "Enter second fraction: "; cin >> c >> dummychar >> d; int numerator = a * d + b * c; int denominator = b * d; cout << "Sum = " << numerator << "/" << denominator << endl; return 0; } Output:

Exercise:

#include using namespace std; int main() { float pound, pence, shillings; cout<<"Enter pounds/*x9c: "; cin>>pound; cout<<"Enter shillings: "; cin>>shillings; cout<<"Enter pence: "; cin>>pence; shillings = (shillings/20); pence = pence/12;

<< setw(15) << "Littletown" << "MI\n"; cout << setw(10) << "O'Brian" << setw(11) << "Coleen" << setw(20) << "42 E. 99th Ave." << setw(15) << "Bigcity" << "NY\n"; cout << setw(10) << "Wong" << setw(11) << "Harry" << setw(20) << "121-A Alabama St." << setw(15) << "Lakeville" << "IL\n"; return 0; } Output:

Exercise:

#include #include using namespace std; int main() {

const int SHILLINGS_PER_POUND = 20; const int PENCE_PER_SHILLING = 12; const int PENCE_PER_POUND = SHILLINGS_PER_POUND * PENCE_PER_SHILLING; float decpounds; cout << "Enter decimal pounds: "; cin >> decpounds; int pounds = static_cast(decpounds); float decfrac = decpounds - pounds; int shillings = static_cast(decfrac * SHILLINGS_PER_POUND); decfrac = decfrac * SHILLINGS_PER_POUND - shillings; int pence = static_cast(decfrac * PENCE_PER_SHILLING); cout << "Equivalent in old notation = £" << pounds << "." << shillings << "." << pence << endl; return 0; } Output:

Chapter:

Exercise:

#include using namespace std; int main(){ int choice; float f, c; cout << "1 to convert Fahrenheit to Celcius,\n2 to convert Celcius to Fahrenheit\nChoice: "; cin >> choice; switch(choice){ case 1: cout << "Enter temperature in Fahrenheit: "; cin >> f;

c = (f - 32) * 5 / 9; cout << "Temperature in Celcius: " << c; break; case 2: cout << "Enter temperature in Celcius: "; cin >> c; f = (1.8 * c) + 32; cout << "Temperature in Fahrenheit: " << f; break; default: cout << "Check the input value and try again either 1 or 2"; break; } cout << endl; return 0; } Output:

Exercise:

#include #include <conio.h> using namespace std; int main() {

char oper, next; do{ cout << "Enter first number, operator, second number: "; cin >> x >> oper >> y; switch(oper){ case '+': ans = x + y; break; case '-': ans = x - y; break; case '*': ans = x * y; break; case '/': ans = x / y; break; default: ans = 0; break; } cout << "Answer: " << ans; cout << "\nDo another calculation (y/n): "; cin >> next; }while(next == 'y'); return 0; } Output:

Exercise:

#include using namespace std; int main() { int height = 20; int width = 1; for (int row = 1; row <= height; row++) { for (int col = 1; col <= width; col++) { cout << "X"; } cout << endl; width += 2; } return 0; } Output:

for (int i = 1; i <= n; i++) { fact *= i; } cout << "Factorial of " << n << " is " << fact << endl; } while (true); cout << "Goodbye!" << endl; return 0; } Output:

Exercise:

#include #include<math.h> using namespace std; int main() { float intial, years, per, total; float interest = 0; cout<<"Enter the initial amount: "; cin>>intial; cout<<"Enter the number of years: "; cin>>years; cout<<"Enter the interest rate(% per year): "; cin>>per; for(int i=1; i<=years; i++) {

interest = per*intial/100; intial += interest; } cout<<"At the end of chosen years , you will have: "<<intial<<endl; return 0; } Output:

Exercis:

#include using namespace std; int main() { char answer; do { int pounds1, shillings1, pence1; int pounds2, shillings2, pence2; char poundSign; cout << "Enter first amount: "; cin >> poundSign >> pounds1 >> poundSign >> shillings1 >> poundSign >> pence1; cout << "Enter second amount: ";