Assignment I Solution

advertisement
Kingdom of Saudi Arabia
Ministry of Higher Education
Majmaah University
Computer Science and Information Technology College
‫المملكة العربية السعودية‬
‫وزارة التعليم العالي‬
‫جامعة المجمعة‬
‫كلية علوم الحاسب وتقنية المعلومات‬
Assignment Due by Sun Sep 23
Assignment 1

Write a complete C++ program to print your name.
#include<iostream>
#include <conio.h>
using namespace std;
int main()
{
cout<< "my name is Rana \n";
getch();
//This function to hold run screen
return 0;
} // end of function main
 Write a complete C++ program that read two numbers from user , then print their sum;
Enter first number please
2
Enter second number please
5
The sum is: 2+5=7
// sum
#include<iostream>
#include <conio.h>
using namespace std;
int main()
{
int num1,num2,sum;
cout<< "enter first number please \n";
cin>>num1;
cout<< "enter second number please \n";
cin>>num2;
sum= num1+num2;
cout<<"the sum is: "<<num1<<"+"<<num2<<"="<<sum;
getch();
//This function to hold run screen
return 0;
} // end of function main
1
Kingdom of Saudi Arabia
Ministry of Higher Education
Majmaah University
Computer Science and Information Technology College

‫المملكة العربية السعودية‬
‫وزارة التعليم العالي‬
‫جامعة المجمعة‬
‫كلية علوم الحاسب وتقنية المعلومات‬
Write a complete C++ program that read 4 numbers from user, print their sum and their
average.
#include <iostream>
using namespace std;
#include <conio.h>
int main()
{
int num1,num2,num3,num4,sum;
double av;
cout<< "enter first number please \n";
cin>>num1;
cout<< "enter second number please \n";
cin>>num2;
cout<< "enter third number please \n";
cin>>num3;
cout<< "enter fourth number please \n";
cin>>num4;
sum= num1+num2+num3+num4;
cout<<"the sum is: "<<num1<<"+"<<num2<<"+"<<num3<<"+"<<num4<<"="<<sum;
av=sum/4.0;
getch();
//This function to hold run screen
return 0;
} // end of function main

Write a complete C++ program that asks the user to enter his salary and employment rank
as following :'S' for a Secretary, 'T' for a Treasurer and 'M' for a manager, then print the
salary with an added 100 S.R bonus if the user is a secretary ,200 S,R for a treasurer,300
S.R for a manager.
Example output:
Enter your salary : 5000
Enter S ,T,M: T
Your salary is 5200
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int salary;
char rank;
cout<<"Enter your salary :
cin>>salary;
2
\n";
Kingdom of Saudi Arabia
Ministry of Higher Education
Majmaah University
Computer Science and Information Technology College
cout<< "Enter T , M , S :\n ";
cin>>rank;
if(rank=='s' || rank=='S')
salary=salary+100;
else
if(rank=='t' || rank=='T')
salary=salary+200;
else
if(rank=='m' || rank=='M')
salary=salary+300;
cout<<"the salary is:"<<salary<<"SR"<<endl;
getch();
return 0;
}
3
//This function to hold run screen
‫المملكة العربية السعودية‬
‫وزارة التعليم العالي‬
‫جامعة المجمعة‬
‫كلية علوم الحاسب وتقنية المعلومات‬
Kingdom of Saudi Arabia
Ministry of Higher Education
Majmaah University
Computer Science and Information Technology College
‫المملكة العربية السعودية‬
‫وزارة التعليم العالي‬
‫جامعة المجمعة‬
‫كلية علوم الحاسب وتقنية المعلومات‬
Guidelines:
1. No Late assignment will be accepted be advised to submitted early.
2. If there is any question, please ask me via r.alabdan@mu.edu.sa
3. Submit your assignment via email write your Name, Group and Course in the
subject line of email. Any emails without subject title will be ignored!
4. After you make sure from your code copy it in a word document and make a
screen shot from your run screen.
1. Windows: press Fn + PrntScr then paste it in Painting apps and save it as
jpg.
2. Mac: press cmd+shift+4 then take a shot from the screen
5. Assignment score is 10
Thank you
Rana Al Abdan
4
Download