0% found this document useful (0 votes)
20 views4 pages

CPP HW 2-2

Hw

Uploaded by

Dilaver Gashi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

CPP HW 2-2

Hw

Uploaded by

Dilaver Gashi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

University of Tirana, Albania

Faculty of Economy
Department Of Statistics & Applied
Informatics
Economics Informatics

"C++ exercise”
Course: C++

Worked by: Fatjona Gashi

Submitted to: Dr. Gloria Tyxhari

Group: IE English

1
Ex.5.17
#include<iostream>
using namespace std;
int main()
{ int counter=1;
int salesunit=0;
int contestantnum=1;
int max;
cout<<"Enter the number of units sold by the contestant:";
cin>>salesunit;
max=salesunit;
while(counter<10)
{ cout<<"Enter the number of units sold by the contestant:";
cin>>salesunit;
counter++;
if(salesunit>max)
{ max=salesunit;
contestantnum=counter;
}}
cout<<"THe contest winner is contestant "<<contestantnum<<" that have
sold "<<max<<" units"<<endl;
return 0; }
Ex 4.20
#include<iostream>
using namespace std;
int main() {
int counter = 0;
int result;
int passes = 0;
int failures = 0;
while(counter < 10) {
do {
cout << "Enter result (1 = pass, 2 = fail) for student " << counter + 1
<< ": ";
cin >> result;
if(result != 1 && result != 2) {
cout << "Invalid input! Please enter 1 for pass or 2 for fail.\n";
}
} while(result != 1 && result != 2);
if(result == 1) {
passes++; }
else {
failures++; }
counter++; }
cout << "Passed: " << passes << "\nFailed: " << failures << endl;
if(passes > 8) {
cout << "Bonus to instructor!" << endl;
}
return 0; }
Ex.4.26

2
#include<iostream>
#include<iomanip>
using namespace std;
int main() {
int size{0};
cout << "Te vendoset brinja e katrorit (me e madhe se 2): ";
cin >> size;
if (size > 2) {
for (int i = 0; i < size; i++) {
cout << "*";
}
cout << endl;
for (int i = 2; i < size; i++) {
cout << "*";
cout << setw(size - 1) << "*" << endl;
}
for (int i = 0; i < size; i++) {
cout << "*";
}
cout << endl;
} else {
cout << "Madhesia duhet te jete me e madhe se 2 dhe numer pozitiv i
plote." << endl;
}
return 0;
}
Ex.4.28
#include<iostream>
using namespace std;
int main()
{
int num;
int num1;
int div1;
int decimal=0;
int y=1;
cout<<"Enter a binary number to convert to decimal:";
cin>>num;
while(num>0){
num1=num%10;
num=num/10;
decimal+=num1*y;
y*=2;
}
cout<<"Numri ne decimal eshte :"<<decimal<<endl;
return 0;
}

Ex.4.34
/*Write a program that reads three nonzero integers and deter

3
mines and prints whether they’re the sides of a right triangle.*/
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cout<<"Enter 3 integers to check if they are the sides of a right triangle:";
cin>>a>>b>>c;
if(a*a==b*b+c*c||b*b==c*c+a*a||c*c==b*b+a*a){
cout<<"Numbers are sides to a right triangle"<<endl;
}
else{
cout<<"They are not the sides of a right triangle"<<endl;
}
return 0;
}

You might also like