C#
assignment 1/assignment 1.docx
Question 1
Test Page
The loop return the summation of 1+2+3+…+n, when n is greater than 0 else the loop return 0
|
Test case |
Expected result |
Actual |
|
>0: input n 10 |
1+2+3+…+10=55 Output: 55 |
Pic 1 |
|
<0: input n -9 |
0 |
Pic 2 |
Pic 1
Pic 2
Question 2
Testing page
The program outputs maximum integer among 100 randomly selected integers.
Question 3
Testing page
When the search key or given integer is existing in the array
When search key does not exist. The program crushes due to runtime error caused by index out of bound.
Question 4
Testing page
Question 5
Testing page
Question 6
n log2 n, lg n, n log n, n, n log n2, n2log n, n2, n3, 2n, n!
Question 7
i. n2 log n
ii. n2 log n2
iii. 2n
image5.png
image6.png
image7.png
image1.png
image2.png
image3.png
image4.png
assignment 1/question2/question2/bin/Debug/question2.exe
assignment 1/question2/question2/bin/Debug/question2.pdb
assignment 1/question2/question2/bin/Debug/question2.vshost.exe
assignment 1/question2/question2/bin/Debug/question2.vshost.exe.manifest
assignment 1/question2/question2/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
assignment 1/question2/question2/obj/x86/Debug/question2.csproj.FileListAbsolute.txt
c:\users\hp touch\documents\visual studio 2010\Projects\question2\question2\bin\Debug\question2.exe c:\users\hp touch\documents\visual studio 2010\Projects\question2\question2\bin\Debug\question2.pdb c:\users\hp touch\documents\visual studio 2010\Projects\question2\question2\obj\x86\Debug\question2.exe c:\users\hp touch\documents\visual studio 2010\Projects\question2\question2\obj\x86\Debug\question2.pdb
assignment 1/question2/question2/obj/x86/Debug/question2.exe
assignment 1/question2/question2/obj/x86/Debug/question2.pdb
assignment 1/question2/question2/Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace question2 { class Program { public static int Max(int[] arr, int n) { int max; max = arr[0]; for (int i = 1; i <= n - 1; i++) if (max < arr[i]) max = arr[i]; return max; } static void Main(string[] args) { int[] arr = new int[100]; Random rand = new Random(); for (int i = 0; i < 100; i++) arr[i] = rand.Next(); int max = Max(arr, 100); Console.WriteLine("Max={0}\n", max); Console.ReadLine(); } } }
assignment 1/question2/question2/Properties/AssemblyInfo.cs
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("question2")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Hewlett-Packard")] [assembly: AssemblyProduct("question2")] [assembly: AssemblyCopyright("Copyright © Hewlett-Packard 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("6491065d-278b-45cb-84d6-822fec8e85ed")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
assignment 1/question2/question2/question2.csproj
Debug x86 8.0.30703 2.0 {58D0C303-A92D-403D-A11A-C15041805BFF} Exe Properties question2 question2 v4.0 Client 512 x86 true full false bin\Debug\ DEBUG;TRACE prompt 4 x86 pdbonly true bin\Release\ TRACE prompt 4
assignment 1/question2/question2.sln
Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "question2", "question2\question2.csproj", "{58D0C303-A92D-403D-A11A-C15041805BFF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {58D0C303-A92D-403D-A11A-C15041805BFF}.Debug|x86.ActiveCfg = Debug|x86 {58D0C303-A92D-403D-A11A-C15041805BFF}.Debug|x86.Build.0 = Debug|x86 {58D0C303-A92D-403D-A11A-C15041805BFF}.Release|x86.ActiveCfg = Release|x86 {58D0C303-A92D-403D-A11A-C15041805BFF}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal
assignment 1/question2/question2.suo
assignment 1/question3/question3/bin/Debug/question3.exe
assignment 1/question3/question3/bin/Debug/question3.pdb
assignment 1/question3/question3/bin/Debug/question3.vshost.exe
assignment 1/question3/question3/bin/Debug/question3.vshost.exe.manifest
assignment 1/question3/question3/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
assignment 1/question3/question3/obj/x86/Debug/question3.csproj.FileListAbsolute.txt
c:\users\hp touch\documents\visual studio 2010\Projects\question3\question3\bin\Debug\question3.exe c:\users\hp touch\documents\visual studio 2010\Projects\question3\question3\bin\Debug\question3.pdb c:\users\hp touch\documents\visual studio 2010\Projects\question3\question3\obj\x86\Debug\question3.exe c:\users\hp touch\documents\visual studio 2010\Projects\question3\question3\obj\x86\Debug\question3.pdb
assignment 1/question3/question3/obj/x86/Debug/question3.exe
assignment 1/question3/question3/obj/x86/Debug/question3.pdb
assignment 1/question3/question3/Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace question3 { class Program { public static int Search(int[] arr, int givenInteger, int n) { int i = 0; while (arr[i] != givenInteger && i <= n - 1) i = i + 1; if (i < n) return i; else return -1; } static void Main(string[] args) { int[] arr = { 10, 78, 45, 7, 86 };//an array Console.WriteLine("Enter integer to search: "); int key = int.Parse(Console.ReadLine()); int index = Search(arr, key, 5);//Search for key in array Console.WriteLine("Index of {0} is {1}\n", key,index); Console.ReadLine(); } } }
assignment 1/question3/question3/Properties/AssemblyInfo.cs
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("question3")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Hewlett-Packard")] [assembly: AssemblyProduct("question3")] [assembly: AssemblyCopyright("Copyright © Hewlett-Packard 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("b6e1cbb9-dc40-4bf0-b918-7b95f4af96d4")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
assignment 1/question3/question3/question3.csproj
Debug x86 8.0.30703 2.0 {FCDFA1FC-2BB3-41FD-9BEE-E195ACB7B50D} Exe Properties question3 question3 v4.0 Client 512 x86 true full false bin\Debug\ DEBUG;TRACE prompt 4 x86 pdbonly true bin\Release\ TRACE prompt 4
assignment 1/question3/question3.sln
Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "question3", "question3\question3.csproj", "{FCDFA1FC-2BB3-41FD-9BEE-E195ACB7B50D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {FCDFA1FC-2BB3-41FD-9BEE-E195ACB7B50D}.Debug|x86.ActiveCfg = Debug|x86 {FCDFA1FC-2BB3-41FD-9BEE-E195ACB7B50D}.Debug|x86.Build.0 = Debug|x86 {FCDFA1FC-2BB3-41FD-9BEE-E195ACB7B50D}.Release|x86.ActiveCfg = Release|x86 {FCDFA1FC-2BB3-41FD-9BEE-E195ACB7B50D}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal
assignment 1/question3/question3.suo
assignment 1/question4/question4/bin/Debug/question4.exe
assignment 1/question4/question4/bin/Debug/question4.pdb
assignment 1/question4/question4/bin/Debug/question4.vshost.exe
assignment 1/question4/question4/bin/Debug/question4.vshost.exe.manifest
assignment 1/question4/question4/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
assignment 1/question4/question4/obj/x86/Debug/question4.csproj.FileListAbsolute.txt
c:\users\hp touch\documents\visual studio 2010\Projects\question4\question4\bin\Debug\question4.exe c:\users\hp touch\documents\visual studio 2010\Projects\question4\question4\bin\Debug\question4.pdb c:\users\hp touch\documents\visual studio 2010\Projects\question4\question4\obj\x86\Debug\question4.exe c:\users\hp touch\documents\visual studio 2010\Projects\question4\question4\obj\x86\Debug\question4.pdb
assignment 1/question4/question4/obj/x86/Debug/question4.exe
assignment 1/question4/question4/obj/x86/Debug/question4.pdb
assignment 1/question4/question4/Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace p2_studentStatistics_obj_nostr { public class student { public int id; public string name; public float score; public student() { Console.WriteLine("Enter student ID, Name, Score line by line"); id = int.Parse(Console.ReadLine()); name = Console.ReadLine(); score = float.Parse(Console.ReadLine()); } } public class StudentStatistics { public float AverageScore(student[] arr, int n) { float sum; sum = 0; for (int i = 0; i < n; i++) sum = sum + arr[i].score; return sum / n; } public float Max(student[] arr, int n)//max function { float max=arr[0].score; for (int i = 1; i < n; i++)//loop if (max < arr[i].score)//condition to determine max max = arr[i].score; return max; } } static class studentApplication { static void Main(string[] args) { int Num; double Ave, max; student[] Stu = new student[100]; Console.WriteLine("Enter the number of students:"); Num = int.Parse(Console.ReadLine()); StudentStatistics stuApp = new StudentStatistics(); for (int i = 0; i < Num; i++) Stu[i] = new student(); Ave = stuApp.AverageScore(Stu, Num); Console.WriteLine("Average Score:{0}\n", Ave); max = stuApp.Max(Stu, Num); Console.WriteLine("Maximum Score:{0}\n", max); Console.ReadLine(); } } }
assignment 1/question4/question4/Properties/AssemblyInfo.cs
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("question4")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Hewlett-Packard")] [assembly: AssemblyProduct("question4")] [assembly: AssemblyCopyright("Copyright © Hewlett-Packard 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("dde64ae2-df48-4822-a50a-135556b9fd98")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
assignment 1/question4/question4/question4.csproj
Debug x86 8.0.30703 2.0 {6F04840F-27FD-431F-9638-337A79035627} Exe Properties p2_studentStatistics_obj_nostr question4 v4.0 Client 512 x86 true full false bin\Debug\ DEBUG;TRACE prompt 4 x86 pdbonly true bin\Release\ TRACE prompt 4
assignment 1/question4/question4.sln
Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "question4", "question4\question4.csproj", "{6F04840F-27FD-431F-9638-337A79035627}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6F04840F-27FD-431F-9638-337A79035627}.Debug|x86.ActiveCfg = Debug|x86 {6F04840F-27FD-431F-9638-337A79035627}.Debug|x86.Build.0 = Debug|x86 {6F04840F-27FD-431F-9638-337A79035627}.Release|x86.ActiveCfg = Release|x86 {6F04840F-27FD-431F-9638-337A79035627}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal
assignment 1/question4/question4.suo
assignment 1/question5/question5/bin/Debug/question5.exe
assignment 1/question5/question5/bin/Debug/question5.pdb
assignment 1/question5/question5/bin/Debug/question5.vshost.exe
assignment 1/question5/question5/bin/Debug/question5.vshost.exe.manifest
assignment 1/question5/question5/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
assignment 1/question5/question5/obj/x86/Debug/question5.csproj.FileListAbsolute.txt
c:\users\hp touch\documents\visual studio 2010\Projects\question5\question5\bin\Debug\question5.exe c:\users\hp touch\documents\visual studio 2010\Projects\question5\question5\bin\Debug\question5.pdb c:\users\hp touch\documents\visual studio 2010\Projects\question5\question5\obj\x86\Debug\question5.exe c:\users\hp touch\documents\visual studio 2010\Projects\question5\question5\obj\x86\Debug\question5.pdb
assignment 1/question5/question5/obj/x86/Debug/question5.exe
assignment 1/question5/question5/obj/x86/Debug/question5.pdb
assignment 1/question5/question5/Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace p2_studentStatistics_obj_struc { public class BookStatistics { public struct book//book struct { public int id; public string title; public int year; public float price; } public BookStatistics(book[] arr, int n)//input details { for (int i = 0; i <= n - 1; i++) { Console.WriteLine("Enter ID, title, published year and price :"); arr[i].id = int.Parse(Console.ReadLine()); arr[i].title = Console.ReadLine(); arr[i].year = int.Parse(Console.ReadLine()); arr[i].price = float.Parse(Console.ReadLine()); } } public double AveragePrice(book[] arr, int n)//calculate average price { float sum; sum = 0; for (int i = 0; i <= n - 1; i++) sum = sum + arr[i].price; return sum / n; } } static class StatisticsApplication { static void Main(string[] args) { int StudentNum; double Ave; Console.WriteLine("Enter the number of books:"); StudentNum = int.Parse(Console.ReadLine()); BookStatistics.book[] a = new BookStatistics.book[100]; BookStatistics stuApp = new BookStatistics(a, StudentNum); Ave = stuApp.AveragePrice(a, StudentNum); Console.WriteLine("Average Price:{0}\n", Ave); Console.ReadLine(); } } }
assignment 1/question5/question5/Properties/AssemblyInfo.cs
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("question5")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Hewlett-Packard")] [assembly: AssemblyProduct("question5")] [assembly: AssemblyCopyright("Copyright © Hewlett-Packard 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("6f27289b-dcbc-4c6b-b462-3601a81848a8")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
assignment 1/question5/question5/question5.csproj
Debug x86 8.0.30703 2.0 {EC378182-1C69-4439-9EC3-A008DFB94A9F} Exe Properties p2_studentStatistics_obj_struc question5 v4.0 Client 512 x86 true full false bin\Debug\ DEBUG;TRACE prompt 4 x86 pdbonly true bin\Release\ TRACE prompt 4
assignment 1/question5/question5.sln
Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "question5", "question5\question5.csproj", "{EC378182-1C69-4439-9EC3-A008DFB94A9F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {EC378182-1C69-4439-9EC3-A008DFB94A9F}.Debug|x86.ActiveCfg = Debug|x86 {EC378182-1C69-4439-9EC3-A008DFB94A9F}.Debug|x86.Build.0 = Debug|x86 {EC378182-1C69-4439-9EC3-A008DFB94A9F}.Release|x86.ActiveCfg = Release|x86 {EC378182-1C69-4439-9EC3-A008DFB94A9F}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal