0% found this document useful (0 votes)
6 views

computer programming

Uploaded by

tolinakidane1015
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

computer programming

Uploaded by

tolinakidane1015
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

DEMBI DOLLO UNIVERSITY

COLLEGE OF Technology DEPARTMENT OF INFORMATION


TECHNOLOGY
BASIC COMPUTER PROGRAMMING GROUP ASSESSMENT Sect(1081)

1. Tolina Kidane seka ID.NO.Dadu NSW /233/22


2.Amanuel Girma ID.NO.Dadu NSW /005/22
3.Gammachu Tashome ID.NO.Dadu NSW /246/22
4.Diribsa Getacho ID.NO.Dadu NSW /215/22
5.Dasalegn Yonas ID.NO.Dadu NSW /213/22
6.Gamachu Yonas ID.NO.Dadu NSW /390/22
7.Adugna Tamiru ID.NO.Dadu NSW/204/22
8.Chara Kena ID.NO.Dadu NSW /211/22
9. Tamesgen Beleta ID.NO.Dadu NSW /230/22

Instructors by Mr. Yadasa


September, 2023
DEMBI DOLO, ETHIOPIA.
1. Find The Most Frequent Element in an Array
#include<iostream>

using namespace std;

void most_occurred_number(int nums[], int size)

int max_count = 0;

cout << "\n Most occurred number: ";

for (int i=0; i<size; i++)

int count=1;

for (int j=i+1;j<size;j++)

if (nums[i]==nums[j])

count++;

if (count>max_count)

max_count = count;

for (int i=0;i<size;i++)

int count=1;

for (int j=i+1;j<size;j++)

if (nums[i]==nums[j])

count++;

if (count==max_count)

cout << nums[i] << endl;

int main()

int nums[] = {4, 5, 9, 12, 9, 22, 45, 7};

int n = sizeof(nums)/sizeof(nums[0]);
cout << "Original array: ";

for (int i=0; i < n; i++)

cout << nums[i] <<" ";

most_occurred_number(nums, n);

2. Program to Convert string to lowercase or uppercase

#include <iostream>
using namespace std;
void lower_string(string str)
{
for(int i=0;str[i]!='\0';i++)
{
if (str[i] >= 'A' && str[i] <= 'Z') //checking for uppercase characters
str[i] = str[i] + 32; //converting uppercase to lowercase
}
cout<<"\n The string in lower case: "<< str;
}
void upper_string(string str)
{
for(int i=0;str[i]!='\0';i++)
{
if (str[i] >= 'a' && str[i] <= 'z') //checking for lowercase characters
str[i] = str[i] - 32; //converting lowercase to uppercase
}
cout<<"\n The string in upper case: "<< str;
}

int main()
{
string str;
cout<<"Enter the string ";
getline(cin,str);
lower_string(str); //function call to convert to lowercase
upper_string(str); //function call to convert to uppercase
return 0;
} } 3. Program to find the vowels in given string #include <iostream>

#include <stdio.h>
using namespace std;
bool isVowel(char c){
// converts char to upper case if it was lowercase
c = toupper(c);

// returns true if any of the condition matches


return c=='A'||c=='E'||c=='I'||c=='O' ||c=='U';
}

int main()
{
char str[100] = "prepinsta";
int vowels = 0;

// can also do str[i] != '\0' in condition below both would work


for(int i = 0; str[i]; i++)
{
if(isVowel(str[i]))
vowels++;

cout << "Total Vowels : " << vowels;

return 0;
}

4. Program to print the next day’s date, month, year


#include <iostream>
using namespace std;

int main() {
int d, m, y;
cout << "Enter today's date in the format: DD MM YYYY\n";
cin >> d >> m >> y;

if (d > 0 && d < 28) { // checking for day from 0 to 27


d += 1;
}
if (d == 28) {
if (m == 2) { // checking for february
if ((y % 400 == 0) || (y % 100 != 0 || y % 4 == 0)) { // leap year check in case of feb
d = 29;
} else {
d = 1;
m = 3;
}
} else { // when it's not feb
d += 1;
}
}
if (d == 29) { // last day check for feb
if (m == 2) {
d = 1;
m = 3;
} else {
d += 1;
}
}
if (d == 30) { // last day check for april, june, september, november
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
d += 1;
} else {
d = 1;
m += 1;
}
}
if (d == 31) { // last day of the month
d = 1;
if (m == 12) { // checking for last day of the year
y += 1;
m = 1;
} else {
m += 1;
}
}

cout << "Tomorrow's date:\n";


if (d < 10) { // checking if day needs to be preceded by 0
cout << "0" << d << " ";
} else {
cout << d << " ";
}
if (m < 10) { // checking if month needs to be preceded by 0
cout << "0" << m << " ";
} else {
cout << m << " ";
}
cout << y;
return 0;
}

Output:

Enter today's date in the format:DD MM YYYY


28 02 2020

Tomorrow's date:
01 03 2020
5. Program to Print a Full Pyramid Using *
// C++ code to demonstrate star Pyramid
#include <iostream>
using namespace std;

// Function to demonstrate printing Pyramid


void pypart2(int n)
{
int i = 0, j = 0, k = 0;
while (i < n) {

// for spacing
while (k <= n - i - 2) {
cout << " ";
k++;
}
k = 0;

// For Pattern printing


while (j <= i) {
cout << "* ";
j++;
}
j = 0;
i++;
cout << endl;
}
}

// Driver Code
int main()
{
int n = 5;

// Function Call
pypart2(n);
return 0;
}

You might also like