0% found this document useful (0 votes)
6 views8 pages

COMP-1431 Student Name: Xavier Adams Student ID: 1260411

The document contains C++ code for three programming questions. The first question calculates the factors of a number and determines if it is a prime, perfect, abundant, or deficient number. The second question simulates a withdrawal process from an ATM, while the third question converts a fraction to a mixed number and calculates the time difference between two given times.

Uploaded by

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

COMP-1431 Student Name: Xavier Adams Student ID: 1260411

The document contains C++ code for three programming questions. The first question calculates the factors of a number and determines if it is a prime, perfect, abundant, or deficient number. The second question simulates a withdrawal process from an ATM, while the third question converts a fraction to a mixed number and calculates the time difference between two given times.

Uploaded by

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

COMP-1431

Student Name: Xavier Adams


Student ID: 1260411

Question 1
#include <iostream>

using namespace std;

int main()

int num1, sum = 0; //varibles

cout<<"Enter A Number Greater then 1 "; //get user input

cin>>num1;

cout<<"The Factors of "<< num1<< " are : "<< "\n";

for(int i = 2; i<num1; i++)

if(num1%i == 0)

sum = sum + i;

cout<<i<<"\n"; //get factors of numbers

if(sum > 1) //see if prime number

cout<<"Sum Of Factors = "<<sum;

if(sum == num1)

cout<<"\n"<<num1<<" Is a Perfect Number"; //perfect number


}

if(sum>num1)

cout<<"\n"<<num1<<" Is a abundant Number";//abundant Number

if(sum<num1)

cout<<"\n"<<num1<<" Is a deficient Number";//deficient Number

else

cout<<"\n"<<num1<<" Is a prime Number"; //Prime Number

Screenshots:
Question 2
#include <iostream>

using namespace std;

int main()

int money,huns = 0,fiftys=0,twentys=0,tens = 0,fives = 0,sum = 0, tryagian = 1; //varibles

while(tryagian == 1)

cout<<"Enter An Amount To Withdrawl (make it a mutiple of 5) "; //get user input

cin>>money;

sum = money;

if(money%5 == 0) //divisable by 5

for(int i; money >= 100; i++) //how many 100's to take out

money = money - 100;

huns++;//add to varible

for(int i; money >= 50; i++)//how many 50's to take out

money = money - 50;

fiftys++;//add to varible
}

for(int i; money >= 20; i++)//how many 20's to take out

money = money - 20;

twentys++;//add to varible

for(int i; money >= 10; i++)//how many 10's to take out

money = money - 10;

tens++;//add to varible

for(int i; money >= 5; i++)//how many 5's to take out

money = money - 5;

fives++; //add to varible

cout<<"Money To be Withdralwed : "<<sum<<"\n"; //print orgian withdrawl amount

cout<<"100's : "<<huns<<"\n"; //print values

cout<<"50's : "<<fiftys<<"\n";

cout<<"20's : "<<twentys<<"\n";

cout<<"10's : "<<tens<<"\n";

cout<<"5's : "<<fives<<"\n";

cout<<"Enter 1 to Withdrawl Agian or 0 to Stop : "; //ask to withdralw agian

cin>>tryagian;

}
else

cout<<"Your Withdralw Ammount is not a multiple of 5 TRY AGIAN "<<"\n"; //withdrawl amount is
not a mutiple of 5

Screenshots:
Question 3
#include <iostream>

using namespace std;

int main()

int N, D, og, rem; //varibles

cout<<"Part 1 - Mixed Fraction Conversion"<< "\n";

cout<<"Enter A numerator "; //get user input

cin>>N;

cout<<"Enter A denominator "; //get user input

cin>>D;

if(D != 0)

og = N/D; //get whole number

rem = N%D;//get ramianind fraction

cout<<N<<"/"<<D<<" = "<<og<<" "<<rem<<"/"<<D; // display whole and mixed fraction

else

cout<<"Error"; //dominator is 0

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////

int h1, h2, m1, m2, t1, t2, finaltime; //varibles

cout<<"\n"<<"\n"<<"Part 2 - Time Difference Calculator"<< "\n"; //assigment 2

cout<<"Enter Time #1"<< "\n";

cout<<"Hour : "; //get user input

cin>>h1;

cout<<"Min : "; //get user input

cin>>m1;

cout<< "\n"<<"Enter Time #2""\n";

cout<<"Hour : "; //get user input

cin>>h2;

cout<<"Min : "; //get user input

cin>>m2;

t1 = (h1 * 60) + m1; //total mins for time 1

t2 = (h2 * 60) + m2;//total mins for time 2

if(t2 >= t1)

finaltime = t2 - t1; //find the diffenece

cout<<"The Diffrence From "<<h1<<":"<<m1<< " to " <<h2<<":"<<m2<< " is :"<<(finaltime /


60)<<"H "<<(finaltime%60)<<" Min"; //Output the diffrence in times

}
else

cout<<"Error : Second time is Greater then First"; //error

Screenshots:

You might also like