Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Computer Programming

Assignment-01

You are required to write the C++ codes for the following tasks. Add suitable
comments in your code for better illustration.
Plagiarism will result in loss of grades.
Tasks:
• Task-01:
#include<iostream>
using namespace std;
int main (){
int a=8;
cout<<"a="<<a<<endl;
cout<<"enter the obtain marks in quiz number1"<<endl;
int d;
cin>>d;
cout<<"obtain marks in quiz number 1="<<d<<endl;
cout<<"enter the obtain marks in quiz number 2="<<endl;
int g;
cin>>g;
cout<<"obtain marks in quiz number 3="<<d<<endl;
int sum=a+d+g;
int y;
y=sum;
cout<<"total sum="<<y<<endl;
double avg=y/3;
cout<<"average of my marks ="<<avg<<endl;

}
Task-02:
#include <iostream>
using namespace std;

int main() {
int Qz_arry[4];
for (int i = 0; i <=4; i++) {
cout << "Enter marks for Quiz " << i + 1 << ": ";
cin >> Qz_arry[i];
}
int j;
for(int j=0;j<=4;j+1){
cout<<"enter the quiz the quiz number which who want see=";
int a;
cin>>a;
cout<<"your obtain marks in this quiz="<<Qz_arry[a]<<endl;
if(Qz_arry[a]>=5){
cout<<"your quiz passed";
}
else{
cout<<"sorry you are fail in this quiz";
}
}
return 0;
}
• Task-03:
#include <iostream>
using namespace std;

int main() {
int num_quizzes;
cout << "Enter the number of quizzes: ";
cin >> num_quizzes;

int Qz_arry[num_quizzes];
for (int i = 0; i <=num_quizzes; ++i) {
cout << "Enter marks for Quiz " << i + 1 << ": ";
cin >> Qz_arry[i];
}

int a;
cout << "Enter the quiz number you want to view: ";
cin >> a;

if (a >= 1 && a <= num_quizzes) {


cout << "Marks for Quiz " << a << ": " << Qz_arry[a - 1] << endl;
} else {
cout << "Invalid quiz number. Please enter a valid quiz number." <<
endl;
}
if( Qz_arry[a - 1] <=5){
cout<<"you are fail in this quiz";
}
else{
cout<<"you are passed the quiz";
}
return 0;
}
Task-04:
#include <iostream>
using namespace std;

int main() {
int num_quizzes;
int countpass=0;
int countfail=0;
cout << "Enter the number of quizzes: ";
cin >> num_quizzes;

int Qz_arry[num_quizzes];
for (int i = 0; i <=num_quizzes; ++i) {
cout << "Enter marks for Quiz " << i + 1 << ": ";
cin >> Qz_arry[i];
}
for (int j = 0; j < num_quizzes+1; ++j) { // Initialize and fix loop condition
if (Qz_arry[j] >= 5) {
countpass++;
} else {
countfail++;
}
}

cout << "Your passed quizzes: " << countpass << endl;
cout << "Your failed quizzes: " << countfail << endl;
}
Task-05:
#include<iostream>
using namespace std;
int main(){
string mypw;
int pwlength;
cout<<"enter your password"<<endl;
cin>>mypw;
int capital=0;
int small=0;
int pwsize;
pwlength=mypw.size() ;
cout<<"your password length="<<pwlength<<endl;
for( int i=0;i<=pwlength;i++){

if (mypw[i] >= 65 && mypw[i] <= 90) {


capital++;
}
else if (mypw[i] >= 97 && mypw[i] <= 122) {
small++;
}
}
if(pwlength>=7&&pwlength<=10&&capital>0&&small>0){
cout<<"password are accepted"<<endl;
}
else{
cout<<"retry"<<endl;
}
cout<<"your password is:"<<mypw<<endl;
}
Task-06:
#include<iostream>
#include <string>
#include <iostream>
#include <string>
using namespace std;
string Mypw;
int pw_length;

int main()
{

cout << "Create your new password"<<endl;


//cin>>Mypw;
getline(cin, Mypw);
pw_length = Mypw.size();
cout <<endl<< "Your entered password is : "<<Mypw<<endl;
cout <<endl<< "Its length is : "<<pw_length<<endl;
if (pw_length<=7 )
cout <<"PW is Accepted"<<endl;
else
cout<<"PLZ RE-Enter Pw"<<endl;
int capital = 0;
int small = 0;
int numeric =0;
int special =0;
for (int i = 0; i < pw_length; i++) {
if (Mypw[i] >= 65 && Mypw[i] <= 90) {
capital++;
}
else if (Mypw[i] >= 97 && Mypw[i] <= 122) {
small++;
}
else if (Mypw[i] >=48 && Mypw[i] <=57){
numeric++;}
else if(Mypw[i] >= 33 && Mypw[i] <= 47){
special++;
}}
if(pw_length<=7&&capital>0&&small>0&&special>0&&numeric>0){
cout<<"password is fullfill the condition"<<endl;
}
else{
cout<<"password not fullfill condition"<<endl;
}
cout<<"capital"<<"="<<capital++<<endl;
cout<<"small"<<"="<<small++<<endl;
cout<<"numeric"<<"="<<numeric++<<endl;
cout<<"special"<<"="<<special++<<endl;
}

You might also like