Professional Documents
Culture Documents
Write a program that prompts the user to enter the year and month, and displays the
number of days in the month.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int days,month,year;
bool leapsum;
cin>>month>>year;
leapsum=((year%4==0)&&(year%100!=0))||(year%400==0);
switch(month){
case 1:case 3: case 5: case 7: case 8: case 10:case 12:
cout<<"31"<<endl;
break;
case 2: if(leapsum){
cout<<"29";
}
else{
cout<<"28";
}
break;
return 0;
}
This study source was downloaded by 100000821935635 from CourseHero.com on 05-29-2022 09:29:21 GMT -05:00
https://www.coursehero.com/file/54858678/C-Finals-practicepdf/
return 2;
}
else {
return n+multiply(n-2);
}
int main()
{
int n=6;
cout<<"enter your number"<<endl;
cin>>n;
cout<<" the sum is "<<multiply(n)<<endl;
return 0;
}
3. Write a program to draw a square with a size of 10 using sleep function to draw star by star
every one second.
Answer=
#include <iostream>
#include <windows.h>
int main()
{
for(int row=0;row<10;row++)
{
for (int col=0;col<10;col++)
if(row<11)
{
if (col==0||row==0||row==9||col==9){
cout<<"* ";
Sleep(1000);
}
else {
cout<<" ";
}
This study source was downloaded by 100000821935635 from CourseHero.com on 05-29-2022 09:29:21 GMT -05:00
https://www.coursehero.com/file/54858678/C-Finals-practicepdf/
}
cout<<endl;
}
return 0;
}
4. Write a program using recursion functions to print backwards. If the user insert @ the
program will stop and print the characters you have been inserted.
Ask the user if he/she wants to play again.
For example.
The program will ask you to insert 1 character : 2
The program will ask you to insert 2 character : R
The program will ask you to insert 3 character : P
The program will ask you to insert 4 character : “space”
The program will ask you to insert 5 character : +
The program will ask you to insert 6 character : +
The program will ask you to insert 7 character : C
The program will ask you to insert 8 character : @
the result: C++ PR2
Answer=
Solution:1
#include <iostream>
#include <cstdio>
This study source was downloaded by 100000821935635 from CourseHero.com on 05-29-2022 09:29:21 GMT -05:00
https://www.coursehero.com/file/54858678/C-Finals-practicepdf/
void printspace(int n){
string b;
return 0;
#include <iostream>
#include <cstdio>
string b;
This study source was downloaded by 100000821935635 from CourseHero.com on 05-29-2022 09:29:21 GMT -05:00
https://www.coursehero.com/file/54858678/C-Finals-practicepdf/
int main()
{
cout<<printspace(1);
return 0;
5. write a C++ function that takes a 2-dimensional integer array with 10 rows and 5
columns as an input and returns the max value of that array and its location within the
array as reference parameters.
Answer.
#include <iostream>
#include <windows.h>
int maximum=z[0][0];
for(int x=0;x<m;x++){
for(int i=0;i<n;i++){
if(z[x][i]>maximum){
maximum=z[x][i];
num[0]=maximum;
num[1]=x;
num[2]=i;
This study source was downloaded by 100000821935635 from CourseHero.com on 05-29-2022 09:29:21 GMT -05:00
https://www.coursehero.com/file/54858678/C-Finals-practicepdf/
return num;
int main()
int student[2][3];
for(int x=0;x<2;x++){
for(int i=0;i<3;i++){
cin>>student[x][i];
int *maximum=findMax(student,2,3);
return 0;
This study source was downloaded by 100000821935635 from CourseHero.com on 05-29-2022 09:29:21 GMT -05:00
https://www.coursehero.com/file/54858678/C-Finals-practicepdf/
using namespace std;
int main()
{
Student a;
cout<<a.getName()<<endl;
Student b;
b.setName("Shakil");
b.setID(110046445);
b.setFaculty("BSEM");
cout<<b.getName()<<endl;
cout<<b.getID()<<endl;
cout<<b.getFaculty()<<endl;
return 0;
}
Student.h
#include <iostream>
#include <string>
public:
Student();
Student(string,int,string);
string getName();
void setName (string);
int getID();
void setID (int);
string getFaculty();
void setFaculty(string);
};
Student.cpp
#include "Student.h"
Student::Student(){
Name="hamza";
ID=110046852;
This study source was downloaded by 100000821935635 from CourseHero.com on 05-29-2022 09:29:21 GMT -05:00
https://www.coursehero.com/file/54858678/C-Finals-practicepdf/
Faculty="FICT";
}
Student::Student(string a,int b,string c){
Name=a;
ID=b;
Faculty=c;
};
string Student::getName(){
return Name;
}
void Student::setName(string a){
Name=a;
}
int Student::getID(){
return ID;
}
void Student::setID(int b){
ID=b;
}
string Student::getFaculty(){
return Faculty;
}
void Student::setFaculty(string c){
Faculty=c;
}
This study source was downloaded by 100000821935635 from CourseHero.com on 05-29-2022 09:29:21 GMT -05:00
https://www.coursehero.com/file/54858678/C-Finals-practicepdf/
Powered by TCPDF (www.tcpdf.org)