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

Lab 7

This C++ program contains 3 code snippets that: 1. Defines a function to check if a year is a leap year by checking if the year is divisible by 4, and uses it in a main function to ask the user for a year and print if it is a leap year or not. 2. Defines a function to count the number of uppercase, lowercase, and digit characters in a string, and calls it in main to get these counts for a user-input string. 3. Gets a name from the user, prints it in lowercase and reverse, and finds the most frequent character by storing character frequencies in an array and finding the maximum.

Uploaded by

Hasnain Abbasi
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)
30 views4 pages

Lab 7

This C++ program contains 3 code snippets that: 1. Defines a function to check if a year is a leap year by checking if the year is divisible by 4, and uses it in a main function to ask the user for a year and print if it is a leap year or not. 2. Defines a function to count the number of uppercase, lowercase, and digit characters in a string, and calls it in main to get these counts for a user-input string. 3. Gets a name from the user, prints it in lowercase and reverse, and finds the most frequent character by storing character frequencies in an array and finding the maximum.

Uploaded by

Hasnain Abbasi
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

#include<iostream>

using namespace std;

bool func(int year){

return (year
%4==0);

main(){
int year;
cout<<"enter year
to check its a leap year ot
not: ";
cin>>year;

if(func(year)){

cout<<year<<" IS A
LEAP YEAR";
}
else {
cout<<"its
not a leapyear";
}

}
#include<iostream>
using namespace std;
void count(char a[100],int &lower,int &upper,int
&digit){

for(int i=0;a[i]!=0;i++){
if( a[i]>='A' && a[i]<='Z'){
upper++;
}
else if(a[i]>='a' &&
a[i]<='z'){
lower++;
}
else if( a[i]>=0 &&
a[i]>=9){
digit++;
}
}

}
int main(){

char a[100];
int lower=0;
int upper=0;
int digit=0;

cout<<"enter a string: ";


cin>>a;
count( a, lower, upper,digit);
cout<<"upper: "<<upper;
cout<<"\nlower: "<<lower;
cout<<"\ndigit: "<<digit;

}
#include<iostream>
#include<cstring>

using namespace std;

main(){

char name[100];
char ch;

cout<<"<---------------
WELCOME To Cringe
Game--------------------->"<<endl;

cout<<"\nenter your Full


name: ";
cin>>name;

cout<<"your name:
"<<name<<endl;
cout<<" lower case: ";
for (int i = 0; i
<strlen(name); i++) {

ch = tolower(name[i]);

cout << ch;


}
int size=strlen(name);

cout<<"\ncount of words:
"<<size<<endl;

strrev(name);

cout<<"your name in reverse:


"<<name<<endl;

int freq[26] = {0};

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


char ch = tolower(name[i]);
if (isalpha(ch)) {
freq[ch - 'a']++;
}
}
char mostFrequentChar = 'a';
int maxFrequency = freq[0];

for (int i = 1; i < 26; i++) {


if (freq[i] > maxFrequency) {
maxFrequency = freq[i];
mostFrequentChar = 'a' + i;
}
}

cout << "\nMost frequent


character: " << mostFrequentChar
<< " (occurs " << maxFrequency
<< " times)" << endl;

You might also like