حل Lab1 مادة برمجة جامعة الامام

  • 2025-10-19

توصيف

Lab 1 (1 page, 6 Exercises)

Exercise 1

Write a C++ program that outputs on the screen the following text: Welcome to the CS140 ''Computer Programming 1'' Lab.

#include <iostream>

using namespace std;
int main() {
    
    cout<<"Welcome to the CS140 "Computer Programming 1" Lab."<<endl;
    
    return 0;
}

Exercise 2

Write a C++ program that outputs on the screen the following patterns:

*****         *****           *                *

*****         *      *         ***           *     *

*****         *      *       *****        *        *

*****         *      *         ***           *     *

*****         *****           *                *

#include <iostream>

using namespace std;
int main() {

    cout<<"*****     *****        *         * "<<endl;
    cout<<"*****     *   *       ***       * * "<<endl;
    cout<<"*****     *   *      *****     *   *"<<endl;
    cout<<"*****     *   *       ***       * * "<<endl;
    cout<<"*****     *****        *         * "<<endl;
    return 0;
}

Exercise 3

Write a C++ program that computes the sum of the different grades (Labs, Midterms, Final) obtained in the CS140 course for a given student. The program should ask the user to enter the grade for each evaluation. You should stick to the following output.

Lab 1 (0 - 10): 6

Lab 2 (0 - 10): 7.5

Midterm 1 (0 - 20): 16.5

Midterm 2 (0 - 20): 18.5

Final (0 - 40) : 26.5

Sum = 75

#include <iostream>
using namespace std;
int main()
{
    int lab1,lab2,midterm1,midterm2,final,sum;
    cout<<"Lab1 (0 - 10): ";
    cin>>lab1;
    cout<<"Lab2 (0 - 10): ";
    cin>>lab2;
    cout<<"midterm1 (0 - 20):";
    cin>>midterm1;
    cout<<"midterm2 (0 - 20):";
    cin>>midterm2;
    cout<<"final (0 - 40): ";
    cin>>final;
    sum=lab1+lab2+midterm1+midterm2+final;
    cout<<"Sum = "<<sum;
    
    return 0;
}

Exercise 4

Write a C++ program determines whether a number n given by the user is even or odd.

#include <iostream>
using namespace std;
int main()
{
    int n;
    cout<<"enter the number";
    cin>>n;
    if(n%2==0)
    {
        cout<<"even";
    }
    else cout<<"odd";
    return 0;
}

Exercise 5

Write a C++ program determines whether a number n given by the user is a multiple of 3 or not.

#include <iostream>
using namespace std;
int main()
{
    int n;
    cout<<"enter the number";
    cin>>n;
    if(n%3==0)
    {
        cout<<"multiple of 3";
    }
    else cout<<"not multiple of 3";
    return 0;
}

Exercise 6

Write a C++ program that determines the maximum of 3 numbers a, b, and c given by the user. 

#include <iostream>
using namespace std;
int main()
{
    int a,b,c;
    cout<<"enter 3 numbers:";
    cin>>a;
    cin>>b;
    cin>>c;
    int max=a;
    if(b>max)
    max=b;
    if(c>max)
    max=c;
    cout<<"biggest number is "<<max;
    return 0;
}

هل كان المحتوى مفيد؟

التعليقات

لاضافة سؤال أو تعليق على المشاركة يتوجب عليك تسجيل الدخول
تسجيل الدخول
محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...